Skip to content

Commit

Permalink
Android: nativeQuit for SDLActivity thread
Browse files Browse the repository at this point in the history
- destroy Android_ActivityMutex
- display any SDL error message that may have occured in this thread,
  since SDL_GetError() is thread specific, and user has no access to it.
  • Loading branch information
1bsyl committed Jan 10, 2019
1 parent dad8161 commit 66fbfe1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Expand Up @@ -405,6 +405,8 @@ protected void onDestroy() {
}
}

SDLActivity.nativeQuit();

super.onDestroy();
}

Expand Down Expand Up @@ -727,6 +729,7 @@ boolean sendCommand(int command, Object data) {
public static native int nativeRunMain(String library, String function, Object arguments);
public static native void nativeLowMemory();
public static native void nativeSendQuit();
public static native void nativeQuit();
public static native void nativePause();
public static native void nativeResume();
public static native void onNativeDropFile(String filename);
Expand Down
22 changes: 22 additions & 0 deletions src/core/android/SDL_android.c
Expand Up @@ -125,6 +125,9 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
JNIEnv *env, jclass cls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
JNIEnv *env, jclass cls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
JNIEnv *env, jclass cls);

Expand Down Expand Up @@ -833,6 +836,25 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
SDL_SemPost(Android_ResumeSem);
}

/* Activity ends */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
JNIEnv *env, jclass cls)
{
const char *str;

if (Android_ActivityMutex) {
SDL_DestroyMutex(Android_ActivityMutex);
Android_ActivityMutex = NULL;
}

str = SDL_GetError();
if (str && str[0]) {
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDLActivity thread ends (error=%s)", str);
} else {
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDLActivity thread ends");
}
}

/* Pause */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
JNIEnv *env, jclass cls)
Expand Down

0 comments on commit 66fbfe1

Please sign in to comment.