summaryrefslogtreecommitdiff
path: root/Source/Android/jni/MainAndroid.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-07-13 03:27:12 +0200
committerGitHub <noreply@github.com>2021-07-13 03:27:12 +0200
commitb09347c16040b4aebe224fc82753da92c49b2731 (patch)
tree359ab5226144a48290693860c71fcc4061ed22cd /Source/Android/jni/MainAndroid.cpp
parent8fcda4c315fd3fbcc0441fec51e499499e03715b (diff)
parent44c99f8cc149e753566ded9331fe824f201c6fe0 (diff)
Merge pull request #9877 from JosJuice/android-early-panic
Android: Avoid crash on early panic alert
Diffstat (limited to 'Source/Android/jni/MainAndroid.cpp')
-rw-r--r--Source/Android/jni/MainAndroid.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp
index 2634cb97e8..e1066f1584 100644
--- a/Source/Android/jni/MainAndroid.cpp
+++ b/Source/Android/jni/MainAndroid.cpp
@@ -175,13 +175,21 @@ void Host_TitleChanged()
static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common::MsgType style)
{
- JNIEnv* env = IDCache::GetEnvForThread();
+ // If a panic alert happens very early in the execution of a game, we can crash here with
+ // the error "JNI NewString called with pending exception java.lang.StackOverflowError".
+ // As a workaround, let's put the call on a new thread with a brand new stack.
+
+ jboolean result;
+
+ std::thread([&] {
+ JNIEnv* env = IDCache::GetEnvForThread();
- // Execute the Java method.
- jboolean result =
- env->CallStaticBooleanMethod(IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(),
- ToJString(env, caption), ToJString(env, text), yes_no,
- style == Common::MsgType::Warning, s_need_nonblocking_alert_msg);
+ // Execute the Java method.
+ result = env->CallStaticBooleanMethod(
+ IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption),
+ ToJString(env, text), yes_no, style == Common::MsgType::Warning,
+ s_need_nonblocking_alert_msg);
+ }).join();
return result != JNI_FALSE;
}