I've been working on a little game for some time now. The initial
Activity instantiates a Surfaceview (MonsterView) with one thread. I
recently added a couple new activities to display high scores and
stuff.
I haven't been able to duplicate my error on the emulator, but on my
phone I can get it to crash sporadically. From the initial activity I
start either of my other activities, then push Back. If I repeat this
enough, my initial activity eventually crashes; sometimes it happens
on the second "Back", sometimes it takes a dozen tries. When it does,
its just a nullpointer exception on the initial activity
10-22 09:15:01.139: DEBUG/KeyInputQueue(81): DebugMonitor keycode=4
value=1
10-22 09:15:01.248: DEBUG/KeyInputQueue(81): DebugMonitor keycode=4
value=0
10-22 09:52:08.138: WARN/dalvikvm(13010): threadid=15: thread exiting
with uncaught exception (group=0x40013140)
10-22 09:52:08.138: ERROR/AndroidRuntime(13010): Uncaught handler:
thread Thread-8 exiting due to uncaught exception
10-22 09:52:08.158: ERROR/AndroidRuntime(13010):
java.lang.NullPointerException
10-22 09:52:08.158: ERROR/AndroidRuntime(13010): at
com.prescience.android.monsterbaiter.MonsterView$MonsterThread.doDraw
(MonsterView.java:2162)
10-22 09:52:08.158: ERROR/AndroidRuntime(13010): at
com.prescience.android.monsterbaiter.MonsterView$MonsterThread.run
(MonsterView.java:1696)
So the random nature of it made me think it's a memory leak. I'm not
sure how to begin diagnosing that, but that's where I was leaning. I
put break points on most of my lifecycle functions to make sure I'm
not creating something repeatedly, but I could have missed something.
My call to fire the new activities look like
Intent i = new Intent(this, MBScoreBoard.class);
startActivityForResult(i, ACTIVITY_SCORES);
And in my Run(), its interesting that it seems to be crashing on Draw
() but it gets through Update() ok...
...
Looper.prepare();
while (IsRunning) {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
update();
if(IsSurfaceCreated)
{
doDraw(c);
}
}
} finally {
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
Looper.loop();
...
For what it's worth, it seems much easier to reproduce when I'm not in
Debug mode.
Any thoughts or suggestions would be much appreciated. I'll be back
if I figure something out.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---