Home > Mobile >  A very strange problem, the code can only be run in debug mode to normal
A very strange problem, the code can only be run in debug mode to normal

Time:12-04

Simple to describe, I set up two classes, A class A, derived from SurfaceView, another class B, derived from the Thread, I wrote A in the class A repaint () mapping method, in class B, which is the new Thread calls the mapping method, we know that the SurfaceView object drawing operations must be lock to get Canvas object, so in class A repaint () method, I add the standard two lines of code to get the Canvas:
SurfaceHolder the holder=this. GetHolder ();
Canvas, Canvas=holder. LockCanvas ();

Problem comes, if I were running directly, then the canvas is not available, always returns null, and if debug mode, and also is the new threads run in class B () method of the entrance position under a breakpoint, interrupt code to run to here and then click continue to run, so the two lines of code is working properly, can always get the correct canvas,

It was amazing, the same code, debug mode to work, instead of the normal operating mode error, the sense that gives a person is code must be on the run () method in hang, can obtain canvas, is really a mystery ~ ~ ~

CodePudding user response:

Test just now, proved my idea, namely the run () method must pause to normal operation.
I was in the run () adds a line: Thread. Sleep (320), everything was normal, & lt; 310. There is so anal.

Do not know to have Daniel can explain the mystery.

CodePudding user response:

You wait for A running again after created B

CodePudding user response:

You have never thought, you complete the canvas is not initialized, began to try to get it?
  • Related