Remove createSDLMainRunnable() in favour of main() to fix multiple issues when providing custom main/runnable code (#10434)

This allows managed applications (eg. Java, C#) to override main() to their liking.
This commit is contained in:
Susko3 2024-08-03 15:34:38 +02:00 committed by GitHub
parent 2f24e9c2f2
commit e3cf20e1cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 26 deletions

View file

@ -64,6 +64,12 @@ JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetVersion)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(
JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeInitSDLThread)(
JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeCleanupSDLThread)(
JNIEnv *env, jclass cls);
JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(
JNIEnv *env, jclass cls,
jstring library, jstring function, jobject array);
@ -188,6 +194,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
static JNINativeMethod SDLActivity_tab[] = {
{ "nativeGetVersion", "()Ljava/lang/String;", SDL_JAVA_INTERFACE(nativeGetVersion) },
{ "nativeSetupJNI", "()I", SDL_JAVA_INTERFACE(nativeSetupJNI) },
{ "nativeInitSDLThread", "()V", SDL_JAVA_INTERFACE(nativeInitSDLThread) },
{ "nativeCleanupSDLThread", "()V", SDL_JAVA_INTERFACE(nativeCleanupSDLThread) },
{ "nativeRunMain", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)I", SDL_JAVA_INTERFACE(nativeRunMain) },
{ "onNativeDropFile", "(Ljava/lang/String;)V", SDL_JAVA_INTERFACE(onNativeDropFile) },
{ "nativeSetScreenResolution", "(IIIIFF)V", SDL_JAVA_INTERFACE(nativeSetScreenResolution) },
@ -764,14 +772,10 @@ JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(nativeAllowRecreateActivity)(
return SDL_AtomicGet(&bAllowRecreateActivity);
}
/* Start up the SDL app */
JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls, jstring library, jstring function, jobject array)
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeInitSDLThread)(
JNIEnv *env, jclass jcls)
{
int status = -1;
const char *library_file;
void *library_handle;
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeRunMain() %d time", run_count);
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeInitSDLThread() %d time", run_count);
if (run_count == 1) {
SDL_AddHintCallback(SDL_HINT_ANDROID_ALLOW_RECREATE_ACTIVITY, SDL_AllowRecreateActivityChanged, NULL);
}
@ -779,6 +783,22 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
/* Save JNIEnv of SDLThread */
Android_JNI_SetEnv(env);
}
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeCleanupSDLThread)(
JNIEnv *env, jclass jcls)
{
/* This is a Java thread, it doesn't need to be Detached from the JVM.
* Set to mThreadKey value to NULL not to call pthread_create destructor 'Android_JNI_ThreadDestroyed' */
Android_JNI_SetEnv(NULL);
}
/* Start up the SDL app */
JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls, jstring library, jstring function, jobject array)
{
int status = -1;
const char *library_file;
void *library_handle;
library_file = (*env)->GetStringUTFChars(env, library, NULL);
library_handle = dlopen(library_file, RTLD_GLOBAL);
@ -853,10 +873,6 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
}
(*env)->ReleaseStringUTFChars(env, library, library_file);
/* This is a Java thread, it doesn't need to be Detached from the JVM.
* Set to mThreadKey value to NULL not to call pthread_create destructor 'Android_JNI_ThreadDestroyed' */
Android_JNI_SetEnv(NULL);
/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
/* exit(status); */