Author Topic: Core thread and shutdown  (Read 1718 times)

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Core thread and shutdown
« 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?
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Core thread and shutdown
« Reply #1 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.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Core thread and shutdown
« Reply #2 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.

2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version