04-14 12:04:30.971 1639-1938/system_process I/WindowManager: Destroying surface Surface(name=Media:com.android.wallpaper.livepicker/com.android.wallpaper.livepicker.LiveWallpaperChange) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
04-14 12:04:30.990 3852-3852/tianranwang.livewallpaper D/MainService: dispose
04-14 12:04:31.018 1639-1990/system_process I/WindowManager: Destroying surface Surface(name=tianranwang.livewallpaper.MainService) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
--------- beginning of crash
04-14 12:04:31.020 3852-4240/tianranwang.livewallpaper E/AndroidRuntime: FATAL EXCEPTION: Animation Thread
Process: tianranwang.livewallpaper, PID: 3852
java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.SurfaceHolder.unlockCanvasAndPost(android.graphics.Canvas)' on a null object reference
at processing.a2d.PGraphicsAndroid2D.endDraw(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PSurfaceNone.callDraw(Unknown Source)
at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)
On the interface “set wallpaper”, I rotated the screen and the sketch(drawing the live wallpaper) restarted, and the app crashed(not always crashed), and the sketch(live wallpaper) kept running on the background..
Could some one give me a hint? Thanks in advance.
The source code ,that i have found in processing.a2d.PGraphicsAndroid2D.endDraw()
from https://github.com/processing/processing-android/tree/master/core/src/processing
public void endDraw() {
if (bitmap == null) return;
// hm, mark pixels as changed, because this will instantly do a full
// copy of all the pixels to the surface.. so that's kind of a mess.
//updatePixels();
// if (primaryGraphics) {
// if (canvas != null) {
// parent.getSurfaceHolder().unlockCanvasAndPost(canvas);
// }
// }
if (primaryGraphics) {
SurfaceHolder holder = parent.getSurface().getSurfaceHolder();
if (holder != null) {
Canvas screen = null;
try {
screen = holder.lockCanvas(null);
if (screen != null) {
screen.drawBitmap(bitmap, new Matrix(), null);
}
} finally {
if (screen != null) {
try {
holder.unlockCanvasAndPost(screen);
} catch (IllegalStateException ex) {
}
}
}
}
} else {
// TODO this is probably overkill for most tasks...
loadPixels();
}
// Marking as modified, and then calling updatePixels() in
// the super class, which just sets the mx1, my1, mx2, my2
// coordinates of the modified area. This avoids doing the
// full copy of the pixels to the surface in this.updatePixels().
setModified();
super.updatePixels();
}
The code above may cause this NullPointerException.
I dont have this problem now, because i update the new version of processing library..And the code above is from the new version of the lib. (I cannot see the code from old version)