From 22770a8f40d4873c85dd901087b00222eafc6ffd Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Wed, 6 Nov 2013 11:23:24 -0300 Subject: [PATCH] [Android] Fixes Bug 2041 - can't get SDL_QUIT event... 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. --- android-project/AndroidManifest.xml | 4 +++- android-project/src/org/libsdl/app/SDLActivity.java | 6 +++--- src/core/android/SDL_android.c | 7 +++++++ src/video/android/SDL_androidevents.c | 4 +++- test/testgles.c | 2 ++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/android-project/AndroidManifest.xml b/android-project/AndroidManifest.xml index 0e4ad416286e2..a05b5660e825f 100644 --- a/android-project/AndroidManifest.xml +++ b/android-project/AndroidManifest.xml @@ -22,7 +22,9 @@ android:allowBackup="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> + android:label="@string/app_name" + android:configChanges="keyboardHidden|orientation" + > diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java index f7cb9abca234e..773ec43bc776c 100644 --- a/android-project/src/org/libsdl/app/SDLActivity.java +++ b/android-project/src/org/libsdl/app/SDLActivity.java @@ -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"); } diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 6fc6f0771cfaf..4c47ae558ddc3 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -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 */ diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c index 9be49cf4f1ed1..7a57ff584a8cf 100644 --- a/src/video/android/SDL_androidevents.c +++ b/src/video/android/SDL_androidevents.c @@ -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 { diff --git a/test/testgles.c b/test/testgles.c index 4e1bc074c0a7a..314ec7cd89d50 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -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; }