PaulsCode Forum

Mupen64Plus AE => General Discussion => Topic started by: littleguy on November 13, 2012, 10:04:13 PM

Title: Core thread and shutdown
Post by: littleguy on November 13, 2012, 10:04:13 PM
Been having a persistent problem that I can't seem to fix from the Java side.  Here goes.  As you know, the SDL surface starts a second thread which calls NativeMethods.init() which gets the whole core running.  Everything works great.  Problem is when we go to quit the core.
 - User clicks to return to main menu
 - UI thread calls finish() on GameActivity
 - Android fires a sequence of lifecycle methods, in the process destroying the SDL surface.
 - In the SDL surfaceDestroyed callback, we call NativeMethods.quit(), and wait for core shutdown and thread join.

Ideally, Android would pop the activity stack to return us to the MainMenu.  Instead, Android pops the stack twice (which I verified with some extra dummy activities) but never crashes.  No warnings or errors in the logcat, everything just as you would expect... except for the extra popped activity.  So it's like something on the C++ side is sending an extra pop.  Have you noticed this or have any ideas what's going on?
Title: Re: Core thread and shutdown
Post by: Paul on November 14, 2012, 06:45:15 AM
Yes I've noticed this but haven't been able to track it down.  I've been using a workaround where I do a System.exit after an intent for the menu activity.  This force-closes SDL before it finished the shutdown sequence.  I'd be interested in a cleaner solution though.  Might be worth looking at SDL 2.0 source, which has advanced considerably since the hacked version we're using.  On the other hand, I'll be removing SDL anyway, so might not be worth a huge effort.
Title: Re: Core thread and shutdown
Post by: littleguy on November 14, 2012, 07:37:03 AM
Gotcha.  Well if we don't want to resort to the harshness of System.exit, as an alternative I could put in a dummy activity between MainActivity and MenuActivity.  Not sure it's really any cleaner though.

In any case, I hear you loud and clear, I'll leave well enough alone and finish the more pressing matters on my plate.  Thanks for the insight.