From dad8161103d41b357e50b17fd4f2ae1b46be40e5 Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Thu, 10 Jan 2019 15:35:46 +0100 Subject: [PATCH] Android: only send Quit event to SDLThread if it's not already terminated And it avoids reporting errors using Android_Pause/ResumeSem that are NULL. --- .../src/main/java/org/libsdl/app/SDLActivity.java | 12 +++++++----- src/core/android/SDL_android.c | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index b47c26789..38c2cd8f4 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -390,16 +390,18 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh return; } - // Send a quit message to the application SDLActivity.mExitCalledFromJava = true; - SDLActivity.nativeQuit(); - // Now wait for the SDL thread to quit if (SDLActivity.mSDLThread != null) { + + // Send Quit event to "SDLThread" thread + SDLActivity.nativeSendQuit(); + + // Wait for "SDLThread" thread to end try { SDLActivity.mSDLThread.join(); } catch(Exception e) { - Log.v(TAG, "Problem stopping thread: " + e); + Log.v(TAG, "Problem stopping SDLThread: " + e); } } @@ -724,7 +726,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh public static native int nativeSetupJNI(); public static native int nativeRunMain(String library, String function, Object arguments); public static native void nativeLowMemory(); - public static native void nativeQuit(); + public static native void nativeSendQuit(); public static native void nativePause(); public static native void nativeResume(); public static native void onNativeDropFile(String filename); diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 96bab018c..981165376 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -122,7 +122,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)( JNIEnv *env, jclass cls); -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)( +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)( JNIEnv *env, jclass cls); JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)( @@ -813,12 +813,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)( SDL_SendAppEvent(SDL_APP_LOWMEMORY); } -/* Quit */ -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)( +/* Send Quit event to "SDLThread" thread */ +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)( JNIEnv *env, jclass cls) { /* Discard previous events. The user should have handled state storage - * in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no + * in SDL_APP_WILLENTERBACKGROUND. After nativeSendQuit() 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 */