diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 4c7345b8dd..3dfafacf7c 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -74,6 +74,7 @@ IniFile s_ini; // sequentially for access. std::mutex s_host_identity_lock; Common::Event s_update_main_frame_event; +Common::Event s_emulation_end_event; bool s_have_wm_user_stop = false; } // Anonymous namespace @@ -282,9 +283,17 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulati JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv* env, jobject obj) { - std::lock_guard guard(s_host_identity_lock); - Core::Stop(); - s_update_main_frame_event.Set(); // Kick the waiting event + { + std::lock_guard guard(s_host_identity_lock); + s_emulation_end_event.Reset(); + Core::Stop(); + + // Kick the waiting event + s_update_main_frame_event.Set(); + } + + // Wait for shutdown, to avoid accessing the config at the same time as the shutdown code + s_emulation_end_event.Wait(); } JNIEXPORT void JNICALL @@ -598,6 +607,8 @@ static void Run(JNIEnv* env, const std::vector& paths, ANativeWindow_release(s_surf); s_surf = nullptr; } + + s_emulation_end_event.Set(); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2(