Android canvas setMatrix (null) crashes (if getMatrix precedes it)

In the example of the lunar lander, if I add the following two lines to the top of the doDraw method, the application will immediately fire with a NullPointerException:

Matrix m = canvas.getMatrix ();
canvas.setMatrix (null);

Stack trace:

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.javahaps60)

The canvas documentation for setMatrix claims that If the matrix parameter is null, then the current matrix is reset to identity, therefore, there is no reason why this should happen.

Also, if I do not call getMatrix before calling setMatrix (null), then setMatrix (null) is successful . So for some reason, this is a combination of two calls that cause a problem.

What is going on here ?!

+3
source share

Source: https://habr.com/ru/post/1769630/


All Articles