Skip to content

Commit

Permalink
Android: on rare occasion, prevent Android_JNI_GetNativeWindow() from…
Browse files Browse the repository at this point in the history
… crashing

If Java getNativeSurface() returns null, then ANativeWindow_fromSurface() would crash().
  • Loading branch information
1bsyl committed Dec 30, 2018
1 parent 1e22fc1 commit 03b0e1d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/android/SDL_android.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 03b0e1d

Please sign in to comment.