Skip to content

Commit

Permalink
Android: only send Quit event to SDLThread if it's not already termin…
Browse files Browse the repository at this point in the history
…ated

And it avoids reporting errors using Android_Pause/ResumeSem that are NULL.
  • Loading branch information
1bsyl committed Jan 10, 2019
1 parent 61d37de commit dad8161
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Expand Up @@ -390,16 +390,18 @@ protected void onDestroy() {
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);
}
}

Expand Down Expand Up @@ -724,7 +726,7 @@ boolean sendCommand(int command, Object data) {
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);
Expand Down
8 changes: 4 additions & 4 deletions src/core/android/SDL_android.c
Expand Up @@ -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)(
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit dad8161

Please sign in to comment.