title: Inconsistent dimensions when surfaceView callback calls surfaceChanged in Android
body: <p>I am using a SurfaceView to draw to a part of the screen, whereby I update the drawing with a background thread. The surfaceview implements a SurfaceView.callback.</p>
  
  <p>On the onDraw method I am using canvas.drawpont(x,y,paint) and draw to pretty much the entire canvas pixel by pixel, so it can be quite intensive on large screens. Anyway, I get an illegalArgumentException if I rotate the phone quickly between landscape and reverse landscape. As Follows:</p>
  
  <pre><code>06-18 15:03:05.853: E/AndroidRuntime(29969): FATAL EXCEPTION: Thread-45
  06-18 15:03:05.853: E/AndroidRuntime(29969): java.lang.IllegalArgumentException
  06-18 15:03:05.853: E/AndroidRuntime(29969):    at Android.view.Surface.unlockCanvasAndPost(Native Method)
  06-18 15:03:05.853: E/AndroidRuntime(29969):    at android.view.SurfaceView$3.unlockCanvasAndPost(SurfaceView.java:793)
  06-18 15:03:05.853: E/AndroidRuntime(29969):    at com.enhancement.SpecGuageUpdate.run(SpecGuageUpdate.java:313)
  </code></pre>
  
  <p>And on SpecGugaeupdate at 313, I have:</p>
  
  <pre><code>mHolder.unlockCanvasAndPost(canvas);
  </code></pre>
  
  <p>Where mHolder is my SurfaceHolder. And of course I have also locked the canvas prior to calling onDraw. </p>
  
  <p>This method works flawlessly if I rotate slowly in every direction, however, the moment I quickly rotate 180degs between the two landscape states it triggers this illegalArgumentException.
  Upon monitoring the width and height in surfaceChanged, I noticed that when I rotate quickly, the width of landscape get paired with the height of portrait. For example, on my phone (Motorola atrix) the dimensions of the SurfaceView for portrait are 540x307 (WidthxHeight), and for landscape are 960x172. This is what happens when I rotate quickly between landscape and reverse landscape:</p>
  
  <p>Rotate to landscape slowly: </p>
  
  <pre><code>960x172
  </code></pre>
  
  <p>Rotate quickly to reverse landscape, surface changed gets called twice.</p>
  
  <pre><code>960x307 - 1st
  960x172 - 2nd
  </code></pre>
  
  <p>I have tried overriding onMeasure and the width and Height are identical to that of SurfaceChanged. So it seems I am trying to draw on a canvas which is not quite ready, but ready enough to be able to lock it to my Holder. Any idea's would be great, thanks for your time.</p>
  
  <p>Additionally, in my surfacedestroyed I am handling my thread like this:</p>
  
  <pre><code>boolean retry = true;
  
              thread.setRunning(false);
                while (retry) {
                      try {
                          specupdate.join();
                          retry = false;
                      } catch (InterruptedException e) {
                      }
                  }
  </code></pre>
  
  <p>Which stops the thread from executing onDraw.</p>