79344765

Date: 2025-01-10 06:21:30
Score: 1
Natty:
Report link

o with specific devices. The only hint I have is that one of the devices it occurred on was a Nexus 7.

NOTE: This is not the same problem as the similar-named question by me. The other question was due to trying to use the canvas before it was available, whereas here it was available.

Below is a sample of my code:

public class GameView extends SurfaceView implements SurfaceHolder.Callback { class GameThread extends Thread { @Override public void run() { while (running) { Canvas c = null; try { c = mSurfaceHolder.lockCanvas();

                synchronized (mSurfaceHolder)
                {
                    long start = System.currentTimeMillis();
                    doDraw(c);
                    long diff = System.currentTimeMillis() - start;

                    if (diff < frameRate)
                        Thread.sleep(frameRate - diff);
                }
            } catch (InterruptedException e)
            {
            }
            finally
            {
                if (c != null)
                {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }
}

public void surfaceCreated(SurfaceHolder holder)
{
    if (gThread.getState() == Thread.State.TERMINATED)
    {
        gThread = new GameThread(getHolder(), getContext(), getHandler());
        gThread.start();
    }
    else
    {
        gThread.start();
    }
}

}

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • User mentioned (1): @Override
  • Low reputation (1):
Posted by: Jhonwindel