fix crash when missing base directory method

This commit is contained in:
qimiko 2024-01-08 17:33:25 -07:00
parent 91c68f525b
commit c1a0969af7
No known key found for this signature in database
GPG key ID: D2D404DD810FE0E3

View file

@ -45,6 +45,17 @@ CCPoint cocos::getMousePos() {
} }
namespace { 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<void**>(&env), JNI_VERSION_1_6) == JNI_OK) {
env->ExceptionClear();
}
}
ghc::filesystem::path getBaseDir() { ghc::filesystem::path getBaseDir() {
JniMethodInfo t; JniMethodInfo t;
std::string path = "/storage/emulated/0/Android/data/com.geode.launcher/files"; std::string path = "/storage/emulated/0/Android/data/com.geode.launcher/files";
@ -54,6 +65,8 @@ namespace {
t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(t.classID);
path = JniHelper::jstring2string(str); path = JniHelper::jstring2string(str);
t.env->DeleteLocalRef(str); t.env->DeleteLocalRef(str);
} else {
clearJNIException();
} }
return ghc::filesystem::path(path); return ghc::filesystem::path(path);