From 9ed4c1375885191971794315cffae5f6a8dd9e34 Mon Sep 17 00:00:00 2001
From: Liam <byteslice@airmail.cc>
Date: Fri, 6 Jan 2023 18:50:01 -0500
Subject: [PATCH] qt: additional fixes for reentrant shutdown

---
 src/yuzu/main.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index c55f81c2f1..2ea3b7d59d 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1839,9 +1839,11 @@ void GMainWindow::OnEmulationStopTimeExpired() {
 
 void GMainWindow::OnEmulationStopped() {
     shutdown_timer.stop();
-    emu_thread->disconnect();
-    emu_thread->wait();
-    emu_thread = nullptr;
+    if (emu_thread) {
+        emu_thread->disconnect();
+        emu_thread->wait();
+        emu_thread.reset();
+    }
 
     if (shutdown_dialog) {
         shutdown_dialog->deleteLater();
@@ -3029,6 +3031,8 @@ void GMainWindow::OnStopGame() {
 
     if (OnShutdownBegin()) {
         OnShutdownBeginDialog();
+    } else {
+        OnEmulationStopped();
     }
 }