From 259eb4b4080a41dcb4717507f0ff43ce65fab743 Mon Sep 17 00:00:00 2001
From: Arisotura <thetotalworm@gmail.com>
Date: Tue, 19 Nov 2024 00:11:46 +0100
Subject: [PATCH] dsfsdhgf

---
 src/frontend/qt_sdl/EmuInstance.cpp | 8 +++++---
 src/frontend/qt_sdl/Window.cpp      | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp
index c6c63e42..f690bdb8 100644
--- a/src/frontend/qt_sdl/EmuInstance.cpp
+++ b/src/frontend/qt_sdl/EmuInstance.cpp
@@ -245,6 +245,8 @@ void EmuInstance::deleteWindow(int id, bool close)
     if (close)
         win->close();
 
+    if (deleting) return;
+
     if (numWindows == 0)
     {
         // if we closed the last window, delete the instance
@@ -1456,16 +1458,16 @@ void EmuInstance::reset()
 
 
 bool EmuInstance::bootToMenu()
-{printf("bootToMenu 1\n");
+{
     // Keep whatever cart is in the console, if any.
     if (!updateConsole())
         // Try to update the console, but keep the existing cart. If that fails...
         return false;
-    printf("bootToMenu 2\n");
+
     // BIOS and firmware files are loaded, patched, and installed in UpdateConsole
     if (nds->NeedsDirectBoot())
         return false;
-    printf("bootToMenu 3\n");
+
     initFirmwareSaveManager();
     nds->Reset();
     setBatteryLevels();
diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp
index eaeebf27..71e4f15a 100644
--- a/src/frontend/qt_sdl/Window.cpp
+++ b/src/frontend/qt_sdl/Window.cpp
@@ -819,6 +819,8 @@ void MainWindow::saveEnabled(bool enabled)
 
 void MainWindow::closeEvent(QCloseEvent* event)
 {
+    if (!emuInstance) return;
+
     if (windowID == 0)
         emuInstance->saveEnabledWindows();
     else