From eb8cd4a7c3448470cbf16aa325b31d997f874bc4 Mon Sep 17 00:00:00 2001 From: mittorn Date: Fri, 1 Dec 2023 16:14:30 +0300 Subject: [PATCH] platform/android-nosdl: add Platform_Shutdown for preShutdown callback --- engine/platform/android/android_nosdl.c | 8 +++++--- engine/platform/android/android_priv.h | 1 + engine/platform/platform.h | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/engine/platform/android/android_nosdl.c b/engine/platform/android/android_nosdl.c index 55f3d3d9..9306ef01 100644 --- a/engine/platform/android/android_nosdl.c +++ b/engine/platform/android/android_nosdl.c @@ -265,6 +265,7 @@ DECLARE_JNI_INTERFACE( int, nativeInit, jobject array ) jni.getGLAttribute = (*env)->GetStaticMethodID(env, jni.bindcls, "getGLAttribute", "(I)I"); jni.deleteGLContext = (*env)->GetStaticMethodID(env, jni.bindcls, "deleteGLContext", "()Z"); jni.getSurface = (*env)->GetStaticMethodID(env, jni.bindcls, "getNativeSurface", "(I)Landroid/view/Surface;"); + jni.preShutdown = (*env)->GetStaticMethodID(env, jni.bindcls, "preShutdown", "()V"); // jni fails when called from signal handler callback, so jump here when called messagebox from handler if( setjmp( crash_frame )) @@ -272,8 +273,7 @@ DECLARE_JNI_INTERFACE( int, nativeInit, jobject array ) // note: this will destroy stack and shutting down engine with return-from-main // will be impossible, but Sys_Quit works (*jni.env)->CallStaticVoidMethod( jni.env, jni.bindcls, jni.messageBox, (*jni.env)->NewStringUTF( jni.env, "crash" ), (*jni.env)->NewStringUTF( jni.env , crash_text ) ); - - // java shutdown callback here? + (*jni.env)->CallStaticVoidMethod( jni.env, jni.bindcls, jni.preShutdown ); // UB, but who cares, we already crashed! longjmp( restore_frame, 1 ); @@ -603,7 +603,9 @@ void Android_Init( void ) void Android_Shutdown( void ) { - + if( host.crashed ) + return; + (*jni.env)->CallStaticVoidMethod( jni.env, jni.bindcls, jni.preShutdown ); } /* diff --git a/engine/platform/android/android_priv.h b/engine/platform/android/android_priv.h index 990c1f85..bad06f81 100644 --- a/engine/platform/android/android_priv.h +++ b/engine/platform/android/android_priv.h @@ -29,6 +29,7 @@ extern struct jnimethods_s jmethodID getGLAttribute; jmethodID deleteGLContext; jmethodID getSurface; + jmethodID preShutdown; int width, height; } jni; diff --git a/engine/platform/platform.h b/engine/platform/platform.h index a4dffb99..fb9a8557 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -135,6 +135,8 @@ static inline void Platform_Shutdown( void ) #if XASH_SDL SDLash_Shutdown( ); +#elif XASH_ANDROID + Android_Shutdown(); #endif }