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.
Sylvain Becker 2019-01-10 15:35:46 +01:00
parent 61d37de099
commit dad8161103
2 changed files with 11 additions and 9 deletions

View File

@ -390,16 +390,18 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return; return;
} }
// Send a quit message to the application
SDLActivity.mExitCalledFromJava = true; SDLActivity.mExitCalledFromJava = true;
SDLActivity.nativeQuit();
// Now wait for the SDL thread to quit
if (SDLActivity.mSDLThread != null) { if (SDLActivity.mSDLThread != null) {
// Send Quit event to "SDLThread" thread
SDLActivity.nativeSendQuit();
// Wait for "SDLThread" thread to end
try { try {
SDLActivity.mSDLThread.join(); SDLActivity.mSDLThread.join();
} catch(Exception e) { } 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 nativeSetupJNI();
public static native int nativeRunMain(String library, String function, Object arguments); public static native int nativeRunMain(String library, String function, Object arguments);
public static native void nativeLowMemory(); public static native void nativeLowMemory();
public static native void nativeQuit(); public static native void nativeSendQuit();
public static native void nativePause(); public static native void nativePause();
public static native void nativeResume(); public static native void nativeResume();
public static native void onNativeDropFile(String filename); public static native void onNativeDropFile(String filename);

View File

@ -122,7 +122,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
JNIEnv *env, jclass cls); JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
JNIEnv *env, jclass cls); JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
@ -813,12 +813,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
SDL_SendAppEvent(SDL_APP_LOWMEMORY); SDL_SendAppEvent(SDL_APP_LOWMEMORY);
} }
/* Quit */ /* Send Quit event to "SDLThread" thread */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)( JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
JNIEnv *env, jclass cls) JNIEnv *env, jclass cls)
{ {
/* Discard previous events. The user should have handled state storage /* 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 */ * events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
/* Inject a SDL_QUIT event */ /* Inject a SDL_QUIT event */