java.lang.IllegalStateException: Surface has already been released.
01-03 11:14:09.312 26780-26808/ddolcatmaster.codeforgame E/AndroidRuntime: FATAL EXCEPTION: Thread-3
Process: ddolcatmaster.codeforgame, PID: 26780
java.lang.IllegalStateException: Surface has already been released.
at android.view.Surface.checkNotReleasedLocked(Surface.java:564)
at android.view.Surface.unlockCanvasAndPost(Surface.java:327)
at android.view.SurfaceView$3.unlockCanvasAndPost(SurfaceView.java:1114)
at ddolcatmaster.codeforgame.GThread.run(GThread.java:34)
@Override
public void run() {
super.run();
while (true){
Canvas canvas = null;
canvas = mHolder.lockCanvas();
try{
synchronized (mHolder){ //다른 스레드와 동기화 유지
canvas.drawBitmap(imageBack,0,0,null);
}
}catch (Exception e){
e.printStackTrace();
}finally {
mHolder.unlockCanvasAndPost(canvas);
}
}
}
Surface가 이미 Released 되었기 때문에 조건문을 추가해야한다.
@Override
public void run() {
super.run();
//스레드로 canvas에 출력
while (true){
Canvas canvas = null;
canvas = mHolder.lockCanvas(); //캔버스를 잠그고
try{
synchronized (mHolder){ //다른 스레드와 동기화 유지
canvas.drawBitmap(imageBack,0,0,null); // 내부 버퍼에 그린다.
}
}catch (Exception e){
e.printStackTrace();
}finally {
if(canvas != null)
mHolder.unlockCanvasAndPost(canvas); //버퍼에 그려진 것을 view로 보낸다.
}
}
}