Android: on rare occasion, prevent Android_JNI_GetNativeWindow() from crashing
authorSylvain Becker <sylvain.becker@gmail.com>
Sun, 30 Dec 2018 22:44:25 +0100
changeset 12490e1e13e154128
parent 12489 ed2da1cc4d4e
child 12491 3b1f484500f0
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
     1.1 --- a/src/core/android/SDL_android.c	Sun Dec 30 15:41:28 2018 +0100
     1.2 +++ b/src/core/android/SDL_android.c	Sun Dec 30 22:44:25 2018 +0100
     1.3 @@ -951,13 +951,15 @@
     1.4  
     1.5  ANativeWindow* Android_JNI_GetNativeWindow(void)
     1.6  {
     1.7 -    ANativeWindow* anw;
     1.8 +    ANativeWindow *anw = NULL;
     1.9      jobject s;
    1.10      JNIEnv *env = Android_JNI_GetEnv();
    1.11  
    1.12      s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
    1.13 -    anw = ANativeWindow_fromSurface(env, s);
    1.14 -    (*env)->DeleteLocalRef(env, s);
    1.15 +    if (s) {
    1.16 +        anw = ANativeWindow_fromSurface(env, s);
    1.17 +        (*env)->DeleteLocalRef(env, s);
    1.18 +    }
    1.19  
    1.20      return anw;
    1.21  }