Android: only send Quit event to SDLThread if it's not already terminated
authorSylvain Becker <sylvain.becker@gmail.com>
Thu, 10 Jan 2019 15:35:46 +0100
changeset 12517608b59e27e10
parent 12516 d1d64b025981
child 12518 f20cacda9d6d
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.
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu Jan 10 15:29:37 2019 +0100
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu Jan 10 15:35:46 2019 +0100
     1.3 @@ -390,16 +390,18 @@
     1.4             return;
     1.5          }
     1.6  
     1.7 -        // Send a quit message to the application
     1.8          SDLActivity.mExitCalledFromJava = true;
     1.9 -        SDLActivity.nativeQuit();
    1.10  
    1.11 -        // Now wait for the SDL thread to quit
    1.12          if (SDLActivity.mSDLThread != null) {
    1.13 +
    1.14 +            // Send Quit event to "SDLThread" thread
    1.15 +            SDLActivity.nativeSendQuit();
    1.16 +
    1.17 +            // Wait for "SDLThread" thread to end
    1.18              try {
    1.19                  SDLActivity.mSDLThread.join();
    1.20              } catch(Exception e) {
    1.21 -                Log.v(TAG, "Problem stopping thread: " + e);
    1.22 +                Log.v(TAG, "Problem stopping SDLThread: " + e);
    1.23              }
    1.24          }
    1.25  
    1.26 @@ -724,7 +726,7 @@
    1.27      public static native int nativeSetupJNI();
    1.28      public static native int nativeRunMain(String library, String function, Object arguments);
    1.29      public static native void nativeLowMemory();
    1.30 -    public static native void nativeQuit();
    1.31 +    public static native void nativeSendQuit();
    1.32      public static native void nativePause();
    1.33      public static native void nativeResume();
    1.34      public static native void onNativeDropFile(String filename);
     2.1 --- a/src/core/android/SDL_android.c	Thu Jan 10 15:29:37 2019 +0100
     2.2 +++ b/src/core/android/SDL_android.c	Thu Jan 10 15:35:46 2019 +0100
     2.3 @@ -122,7 +122,7 @@
     2.4  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
     2.5          JNIEnv *env, jclass cls);
     2.6  
     2.7 -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
     2.8 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
     2.9          JNIEnv *env, jclass cls);
    2.10  
    2.11  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
    2.12 @@ -813,12 +813,12 @@
    2.13      SDL_SendAppEvent(SDL_APP_LOWMEMORY);
    2.14  }
    2.15  
    2.16 -/* Quit */
    2.17 -JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
    2.18 +/* Send Quit event to "SDLThread" thread */
    2.19 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
    2.20                                      JNIEnv *env, jclass cls)
    2.21  {
    2.22      /* Discard previous events. The user should have handled state storage
    2.23 -     * in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
    2.24 +     * in SDL_APP_WILLENTERBACKGROUND. After nativeSendQuit() is called, no
    2.25       * events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
    2.26      SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
    2.27      /* Inject a SDL_QUIT event */