Android: Fix crash on startup

This commit is contained in:
Connor McLaughlin 2020-10-14 18:36:25 +10:00
parent 8b6309aff6
commit e78ea2b60e
1 changed files with 17 additions and 5 deletions

View File

@ -53,14 +53,27 @@ void AndroidSettingsInterface::Clear()
int AndroidSettingsInterface::GetIntValue(const char* section, const char* key, int default_value /*= 0*/)
{
JNIEnv* env = AndroidHelpers::GetJNIEnv();
#if 0
return static_cast<int>(env->CallIntMethod(m_java_shared_preferences, m_get_int,
env->NewStringUTF(GetSettingKey(section, key)), default_value));
#else
// Some of these settings are string lists...
jstring string_object = reinterpret_cast<jstring>(
env->CallObjectMethod(m_java_shared_preferences, m_get_string, env->NewStringUTF(GetSettingKey(section, key)),
env->NewStringUTF(TinyString::FromFormat("%d", default_value))));
if (env->ExceptionCheck())
{
env->ExceptionClear();
// it might actually be an int (e.g. seek bar preference)
const int int_value = static_cast<int>(env->CallIntMethod(m_java_shared_preferences, m_get_int,
env->NewStringUTF(GetSettingKey(section, key)), default_value));
if (env->ExceptionCheck())
{
env->ExceptionClear();
return default_value;
}
return int_value;
}
if (!string_object)
return default_value;
@ -70,7 +83,6 @@ int AndroidSettingsInterface::GetIntValue(const char* section, const char* key,
std::optional<int> value = StringUtil::FromChars<int>(data);
env->ReleaseStringUTFChars(string_object, data);
return value.value_or(default_value);
#endif
}
float AndroidSettingsInterface::GetFloatValue(const char* section, const char* key, float default_value /*= 0.0f*/)