Skip to content

Commit 7fa9216

Browse files
committed
Android: Don't call NativeLibrary methods during class init
There's no guarantee that directory initialization has completed by this point, so we can't safely use NativeLibrary. I'm making this change because of a crash being reported in Google Play Console. The exact way it's crashing is mysterious to me, so I'm not sure if this commit fixes the crash, but I think this commit is a reasonable change to make even if it doesn't fix the crash. Backtrace from Google Play Console: #00 pc 0x0000000000469074 /data/app/~~m0kqybFNfeqnDenQFc53XQ==/org.dolphinemu.dolphinemu-Mtaw0lU8DVUQbte2ZjBp3w==/lib/arm64/libmain.so (std::__ndk1::pair<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>::pair[abi:nn180000]<char const* const&, char const* const&, 0>(char const* const&, char const* const&)) (BuildId: 64cfebf5b574b6729ebc51799aa94ccc3238cbcc) #1 pc 0x0000000000468e9c /data/app/~~m0kqybFNfeqnDenQFc53XQ==/org.dolphinemu.dolphinemu-Mtaw0lU8DVUQbte2ZjBp3w==/lib/arm64/libmain.so (std::__ndk1::pair<std::__ndk1::__tree_iterator<std::__ndk1::__value_type<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>, std::__ndk1::__tree_node<std::__ndk1::__value_type<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>, void*>*, long>, bool> std::__ndk1::__tree<std::__ndk1::__value_type<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>, std::__ndk1::__map_value_compare<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::__value_type<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>, std::__ndk1::less<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>, true>, std::__ndk1::allocator<std::__ndk1::__value_type<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>>>>::__emplace_unique_impl<char const* const&, char const* const&>(char const* const&, char const* const&)) (BuildId: 64cfebf5b574b6729ebc51799aa94ccc3238cbcc) #2 pc 0x0000000000462f08 /data/app/~~m0kqybFNfeqnDenQFc53XQ==/org.dolphinemu.dolphinemu-Mtaw0lU8DVUQbte2ZjBp3w==/lib/arm64/libmain.so (Common::Log::LogManager::GetLogTypes()) (BuildId: 64cfebf5b574b6729ebc51799aa94ccc3238cbcc) #3 pc 0x000000000044339c /data/app/~~m0kqybFNfeqnDenQFc53XQ==/org.dolphinemu.dolphinemu-Mtaw0lU8DVUQbte2ZjBp3w==/lib/arm64/libmain.so (Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames+56) (BuildId: 64cfebf5b574b6729ebc51799aa94ccc3238cbcc) #4 pc 0x000000000031456c /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (art_jni_trampoline+108) #5 pc 0x0000000000781508 /apex/com.android.art/lib64/libart.so (nterp_helper+152) dolphin-emu#6 pc 0x00000000002d94d4 /data/app/~~m0kqybFNfeqnDenQFc53XQ==/org.dolphinemu.dolphinemu-Mtaw0lU8DVUQbte2ZjBp3w==/base.apk (org.dolphinemu.dolphinemu.features.settings.ui.SettingsFragmentPresenter.<clinit>+16) [...]
1 parent 805307f commit 7fa9216

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ class SettingsFragmentPresenter(
19611961
IntSetting.LOGGER_VERBOSITY,
19621962
R.string.log_verbosity,
19631963
0,
1964-
logVerbosityEntries, logVerbosityValues
1964+
getLogVerbosityEntries(), getLogVerbosityValues()
19651965
)
19661966
)
19671967
sl.add(
@@ -1993,7 +1993,7 @@ class SettingsFragmentPresenter(
19931993
) { SettingsAdapter.clearLog() })
19941994

19951995
sl.add(HeaderSetting(context, R.string.log_types, 0))
1996-
for (logType in LOG_TYPE_NAMES) {
1996+
for (logType in NativeLibrary.GetLogTypeNames()) {
19971997
sl.add(LogSwitchSetting(logType.first, logType.second, ""))
19981998
}
19991999
}
@@ -2543,7 +2543,7 @@ class SettingsFragmentPresenter(
25432543
fun setAllLogTypes(value: Boolean) {
25442544
val settings = fragmentView.settings
25452545

2546-
for (logType in LOG_TYPE_NAMES) {
2546+
for (logType in NativeLibrary.GetLogTypeNames()) {
25472547
AdHocBooleanSetting(
25482548
Settings.FILE_LOGGER,
25492549
Settings.SECTION_LOGGER_LOGS,
@@ -2604,26 +2604,29 @@ class SettingsFragmentPresenter(
26042604
}
26052605

26062606
companion object {
2607-
private val LOG_TYPE_NAMES = NativeLibrary.GetLogTypeNames()
26082607
const val ARG_CONTROLLER_TYPE = "controller_type"
26092608
const val ARG_SERIALPORT1_TYPE = "serialport1_type"
26102609

26112610
// Value obtained from LogLevel in Common/Logging/Log.h
2612-
private val logVerbosityEntries: Int
2613-
get() =
2614-
if (NativeLibrary.GetMaxLogLevel() == 5) {
2615-
R.array.logVerbosityEntriesMaxLevelDebug
2616-
} else {
2617-
R.array.logVerbosityEntriesMaxLevelInfo
2618-
}
2611+
private fun getLogVerbosityEntries(): Int {
2612+
// GetMaxLogLevel is effectively a constant, but we can't call it before loading
2613+
// the native library
2614+
return if (NativeLibrary.GetMaxLogLevel() == 5) {
2615+
R.array.logVerbosityEntriesMaxLevelDebug
2616+
} else {
2617+
R.array.logVerbosityEntriesMaxLevelInfo
2618+
}
2619+
}
26192620

26202621
// Value obtained from LogLevel in Common/Logging/Log.h
2621-
private val logVerbosityValues: Int
2622-
get() =
2623-
if (NativeLibrary.GetMaxLogLevel() == 5) {
2624-
R.array.logVerbosityValuesMaxLevelDebug
2625-
} else {
2626-
R.array.logVerbosityValuesMaxLevelInfo
2627-
}
2622+
private fun getLogVerbosityValues(): Int {
2623+
// GetMaxLogLevel is effectively a constant, but we can't call it before loading
2624+
// the native library
2625+
return if (NativeLibrary.GetMaxLogLevel() == 5) {
2626+
R.array.logVerbosityValuesMaxLevelDebug
2627+
} else {
2628+
R.array.logVerbosityValuesMaxLevelInfo
2629+
}
2630+
}
26282631
}
26292632
}

0 commit comments

Comments
 (0)