I have a problem with a drawing application. I have the error below when I leave the drawing activity (with the return button for example). I've looked at the posts but nothing seems to help me. Please, it would mean a lot if you could have a look at my drawingsurface activity, because I've been trying to make it work for a while! Thanks a lot :)
Error :
03-25 13:41:36.760: E/AndroidRuntime(6642): FATAL EXCEPTION: Thread-423
03-25 13:41:36.760: E/AndroidRuntime(6642): java.lang.IllegalArgumentException
03-25 13:41:36.760: E/AndroidRuntime(6642): at android.view.Surface.nativeUnlockCanvasAndPost(Native Method)
03-25 13:41:36.760: E/AndroidRuntime(6642): at android.view.Surface.unlockCanvasAndPost(Surface.java:457)
03-25 13:41:36.760: E/AndroidRuntime(6642): at android.view.SurfaceView$4.unlockCanvasAndPost(SurfaceView.java:812)
03-25 13:41:36.760: E/AndroidRuntime(6642): at com.ecp.drawing.DrawingSurface$DrawThread.run(DrawingSurface.java:80)
Main code of DrawingSurface :
public void run() {
Canvas canvas = null;
while (_run){
if(isDrawing == true){
try{
canvas = mSurfaceHolder.lockCanvas(null);
if(mBitmap == null){
mBitmap = Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);
}
final Canvas c = new Canvas (mBitmap);
c.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
commandManager.executeAll(c,previewDoneHandler);
previewPath.draw(c);
canvas.drawBitmap (mBitmap, 0, 0,null);
} finally {
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
There is already a surface destroyed function :
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
boolean retry = true;
thread.setRunning(false);
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
// we will try it again and again...
}
}
}