Skip to content

Commit

Permalink
[Android] Fixes Bug 2041 - can't get SDL_QUIT event...
Browse files Browse the repository at this point in the history
Thanks to Denis Bernard!

Also, changed the Android manifest so the app doesn't quit with orientation
changes, and made testgles.c exit properly on Android.
  • Loading branch information
gabomdq committed Nov 6, 2013
1 parent e27248c commit 22770a8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion android-project/AndroidManifest.xml
Expand Up @@ -22,7 +22,9 @@
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="SDLActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
6 changes: 3 additions & 3 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -121,13 +121,13 @@ protected void onDestroy() {
SDLActivity.nativeQuit();

// Now wait for the SDL thread to quit
if (mSDLThread != null) {
if (SDLActivity.mSDLThread != null) {
try {
mSDLThread.join();
SDLActivity.mSDLThread.join();
} catch(Exception e) {
Log.v("SDL", "Problem stopping thread: " + e);
}
mSDLThread = null;
SDLActivity.mSDLThread = null;

//Log.v("SDL", "Finished waiting for SDL thread");
}
Expand Down
7 changes: 7 additions & 0 deletions src/core/android/SDL_android.c
Expand Up @@ -283,9 +283,16 @@ void Java_org_libsdl_app_SDLActivity_nativeLowMemory(
void Java_org_libsdl_app_SDLActivity_nativeQuit(
JNIEnv* env, jclass cls)
{
/* Discard previous events. The user should have handled state storage
* in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
* events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
/* Inject a SDL_QUIT event */
SDL_SendQuit();
SDL_SendAppEvent(SDL_APP_TERMINATING);
/* Resume the event loop so that the app can catch SDL_QUIT which
* should now be the top event in the event queue. */
if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
}

/* Pause */
Expand Down
4 changes: 3 additions & 1 deletion src/video/android/SDL_androidevents.c
Expand Up @@ -82,7 +82,9 @@ Android_PumpEvents(_THIS)
isPaused = 0;

/* Restore the GL Context from here, as this operation is thread dependent */
android_egl_context_restore();
if (!SDL_HasEvent(SDL_QUIT)) {
android_egl_context_restore();
}
}
}
else {
Expand Down
2 changes: 2 additions & 0 deletions test/testgles.c
Expand Up @@ -335,7 +335,9 @@ main(int argc, char *argv[])
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
}
#if !defined(__ANDROID__)
quit(0);
#endif
return 0;
}

Expand Down

0 comments on commit 22770a8

Please sign in to comment.