From c1a0969af7e63dd0401681339b642eb1a0eb56f0 Mon Sep 17 00:00:00 2001 From: qimiko <25387744+qimiko@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:33:25 -0700 Subject: [PATCH] fix crash when missing base directory method --- loader/src/platform/android/util.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/loader/src/platform/android/util.cpp b/loader/src/platform/android/util.cpp index 126833be..38eed6e7 100644 --- a/loader/src/platform/android/util.cpp +++ b/loader/src/platform/android/util.cpp @@ -45,6 +45,17 @@ CCPoint cocos::getMousePos() { } namespace { + void clearJNIException() { + // this is a silly workaround to not crash when the method is not found. + // cocos figured this out half a year later... + auto vm = JniHelper::getJavaVM(); + + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) == JNI_OK) { + env->ExceptionClear(); + } + } + ghc::filesystem::path getBaseDir() { JniMethodInfo t; std::string path = "/storage/emulated/0/Android/data/com.geode.launcher/files"; @@ -54,6 +65,8 @@ namespace { t.env->DeleteLocalRef(t.classID); path = JniHelper::jstring2string(str); t.env->DeleteLocalRef(str); + } else { + clearJNIException(); } return ghc::filesystem::path(path);