From 7ad71563ce8a3b88ce5fe047dd8f30046a2a3d32 Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Fri, 25 Sep 2020 10:42:07 +0200 Subject: [PATCH] Android: be sure shared libraries are loaded in onConfigurationChanged() This could fix a rare crash if: - onConfigurationChanged is called before onCreate(); or shared libraries failed to load and onConfigurationChanged() is called --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index aa1df34fbd..b5c3193f51 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -71,7 +71,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh public static NativeState mCurrentNativeState; /** If shared libraries (e.g. SDL or the native application) could not be loaded. */ - public static boolean mBrokenLibraries; + public static boolean mBrokenLibraries = true; // Main components protected static SDLActivity mSingleton; @@ -174,7 +174,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh mCursors = new Hashtable(); mLastCursorID = 0; mSDLThread = null; - mBrokenLibraries = false; mIsResumedCalled = false; mHasFocus = true; mNextNativeState = NativeState.INIT; @@ -199,6 +198,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh String errorMsgBrokenLib = ""; try { loadLibraries(); + mBrokenLibraries = false; /* success */ } catch(UnsatisfiedLinkError e) { System.err.println(e.getMessage()); mBrokenLibraries = true; @@ -420,6 +420,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh Log.v(TAG, "onConfigurationChanged()"); super.onConfigurationChanged(newConfig); + if (SDLActivity.mBrokenLibraries) { + return; + } + if (mCurrentLocale == null || !mCurrentLocale.equals(newConfig.locale)) { mCurrentLocale = newConfig.locale; SDLActivity.onNativeLocaleChanged();