In the lunar lander example, if I add the following two lines to the top of the doDraw method, the app crashes immediately with a NullPointerException:
Matrix m = canvas.getMatrix(); canvas.setMatrix( null );
Stack trace is:
FATAL EXCEPTION: Thread-8 java.lang.NullPointerException at android.graphics.Matrix.preConcat(Matrix.java:233) at android.view.Surface$CompatibleCanvas.setMatrix(Surface.java:259) at com.example.android.lunarlander.LunarView$LunarThread.doDraw(LunarView.java:617) at com.example.android.lunarlander.LunarView$LunarThread.run(LunarView.java:360)
The canvas documentation for setMatrix states that "If the matrix parameter is null, then the current matrix is reset to identity", so there's no reason this should crash.
Also, if I do not call getMatrix before calling setMatrix(null), then setMatrix(null) is successful. So somehow it is the combination of the two calls that are causing a problem.
Whats going on here?!