Exiting android game loop

I was reading this article:
https://forums.libsdl.org/viewtopic.php?t=9853&sid=015c4716f861c7491ec21972d2edefea

it seems to state avoid using exit(0); from my c source on
case SDLK_AC_BACK:

but using sdl_quit(); causes the application to hang and then if I click
the app icon it’ll just open and immediately close but the last frame is
still rendered.

What’s the way to properly exit an android app? It probably applies to all
mobile devices as well.

You should end your gameloop, and before your int main() returns, call
SDL_Quit(). Also shutdown and cleanup any other things that need
shutdown handling.

On Android, when an app quits, the memory is not necessarily
deinitialized. In particular, static variables are problematic because
they will not be reinitialized on the next run unless Android has
purged this memory somehow (force kill, reboot, reaping). If your app
is hanging on the next run, this is probably due to some static
variable that has a value from the previous run and is not getting
reinitialized. So you need to make sure you clean these up. Calling
exit() basically kills the app which avoids this problem, but is a
really bad thing to do on Android for other reasons.

-EricOn 8/20/15, Owen Alanzo Hogarth wrote:

I was reading this article:
https://forums.libsdl.org/viewtopic.php?t=9853&sid=015c4716f861c7491ec21972d2edefea

it seems to state avoid using exit(0); from my c source on
case SDLK_AC_BACK:

but using sdl_quit(); causes the application to hang and then if I click
the app icon it’ll just open and immediately close but the last frame is
still rendered.

What’s the way to properly exit an android app? It probably applies to all
mobile devices as well.

Its always a good idea to shutdown sdl_mixer, sdl_image etc before calling SDL_Quit too…

thanks for the tips, it seems if I call SDL_Quit(); android hangs and if I
try to reopen the app it just auto exits again until I force close the app.

calling exit(0); for android seems to work the best. So far it’s worked the
best by catching the android exit call, quitting image, mixer, saving
whatever data I need to save then calling exit(0);

thanks for all the tips.On Fri, Aug 21, 2015 at 7:28 PM, MrTAToad wrote:

Its always a good idea to shutdown sdl_mixer, sdl_image etc before calling
SDL_Quit too…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I had similar issues myself with 2.0.3. I ended up disabling the back
button then (horrible I know). Now I use the latest hg version of SDL and
SDL_Quit() quits the application properly. It seems they fixed it after
2.0.3. I suggest you try the hg version.

  • MagnusOn Fri, Aug 21, 2015, 14:28 Owen Alanzo Hogarth wrote:

thanks for the tips, it seems if I call SDL_Quit(); android hangs and if I
try to reopen the app it just auto exits again until I force close the app.

calling exit(0); for android seems to work the best. So far it’s worked
the best by catching the android exit call, quitting image, mixer, saving
whatever data I need to save then calling exit(0);

thanks for all the tips.

On Fri, Aug 21, 2015 at 7:28 PM, MrTAToad wrote:

Its always a good idea to shutdown sdl_mixer, sdl_image etc before
calling SDL_Quit too…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org