summaryrefslogtreecommitdiff
path: root/Source/Android/jni/MainAndroid.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-08-08 16:22:52 +0200
committerJosJuice <josjuice@gmail.com>2021-09-21 16:33:57 +0200
commit3eb07e977269b6d2ddd126f78acd6d4b4a219e71 (patch)
tree730e05febabb19b04357016075389825c080b3e5 /Source/Android/jni/MainAndroid.cpp
parent446e2d9119a3c4281e72feefca9bbcd2b1eb21e3 (diff)
Android: Don't rely on onPause for pausing before destroying surface
Fixes a crash which was uncovered (or just made more likely?) by the previous commit.
Diffstat (limited to 'Source/Android/jni/MainAndroid.cpp')
-rw-r--r--Source/Android/jni/MainAndroid.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp
index 1b54cd592c..53a87da1bc 100644
--- a/Source/Android/jni/MainAndroid.cpp
+++ b/Source/Android/jni/MainAndroid.cpp
@@ -443,7 +443,25 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChang
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv*,
jclass)
{
- std::lock_guard<std::mutex> guard(s_surface_lock);
+ {
+ // If emulation continues running without a valid surface, we will probably crash,
+ // so pause emulation until we get a valid surface again. EmulationFragment handles resuming.
+
+ std::unique_lock host_identity_guard(s_host_identity_lock);
+
+ while (s_is_booting.IsSet())
+ {
+ // Need to wait for boot to finish before we can pause
+ host_identity_guard.unlock();
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ host_identity_guard.lock();
+ }
+
+ if (Core::GetState() == Core::State::Running)
+ Core::SetState(Core::State::Paused);
+ }
+
+ std::lock_guard surface_guard(s_surface_lock);
if (g_renderer)
g_renderer->ChangeSurface(nullptr);