I've made a litte game using the GLSurfaceView from the SpriteMethodTest example, from my main activity I'm calling GLSurfaceView.setEvent(new UpdateThread); to set this as the "GLThread" and fire it off.
- Code: Select all
public void onCreate(Bundle savedInstanceState)
{
GLSurfaceView view = new GLSurfaceView(this);
GLRenderer renderer = new GLRenderer(this);
view.setRenderer(renderer);
setContentView(view);
// my object pool code gets set up here, a few objects get added which will get rendered and updated later
view.setEvent(new UpdateThread());
}
All works well, infact I've had a few interesting non-thread safe bugs I've bumped into to confirm it's definitely splitting the updating/rendering correctly. The issue comes from when I close the application with the back button curiously, if I then go to the applications menu and load it again, it seems the runnable UpdateThread() is getting run twice!
The thread triggers an enemy to spawn every 2 seconds, after the restart I've often got 2 spawning in that 2 second window, close and reopen a few more times and I get dozens spawning. It liteally goes through onCreate so t obviously thinks it's previously dead.
On closing it does go through:
- Code: Select all
Activity.onPause/onStop/onDestroy
which fires off:
- Code: Select all
mGLThread.requestExitAndWait()
which in turn successfully sets mDone to true on the thread, getting it out of it's while() loop. I'm baffled, should I be forcibly calling "stop" on the runnable or something? The implementation seems exactly the same as the demo. I can forcibly kill the thread from Taskiller or similar and it restarts fine the next time, it just doesn't seem to be shutting down tidily.
Failing that does anyone know of any good render/update threading examples? I'm not even convinced setEvent is the best way for me to go, it seems to just pass all the messages via a bulky class in the first place.
Thanks!


