From 03b0e1dee03494c04ebb5d391fbcea06e276d8f8 Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Sun, 30 Dec 2018 22:44:25 +0100 Subject: [PATCH] Android: on rare occasion, prevent Android_JNI_GetNativeWindow() from crashing If Java getNativeSurface() returns null, then ANativeWindow_fromSurface() would crash(). --- src/core/android/SDL_android.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 308cd6f436d45..dd20a2bb0b2e7 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -951,13 +951,15 @@ static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder) ANativeWindow* Android_JNI_GetNativeWindow(void) { - ANativeWindow* anw; + ANativeWindow *anw = NULL; jobject s; JNIEnv *env = Android_JNI_GetEnv(); s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface); - anw = ANativeWindow_fromSurface(env, s); - (*env)->DeleteLocalRef(env, s); + if (s) { + anw = ANativeWindow_fromSurface(env, s); + (*env)->DeleteLocalRef(env, s); + } return anw; }