diff --git a/src/emulator.cpp b/src/emulator.cpp index 3ae745a1e..1e9a4fd81 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -295,6 +295,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector recentFiles = Config::getRecentFiles(); - if (recentFiles.empty()) { + if (lastGamePath.empty()) { QMessageBox::warning(this, tr("Restart Game"), tr("No recent game found.")); return; } - QString lastGamePath = QString::fromStdString(recentFiles.front()); - - // Stop the current game first + // Stop the current game properly StopGame(); - // Wait for cleanup - QThread::sleep(1); + // Ensure the game has fully stopped before restarting + while (isGameRunning) { + QCoreApplication::processEvents(); + QThread::msleep(100); // Small delay to allow cleanup + } - // Restart the game - StartEmulator(Common::FS::PathFromQString(lastGamePath)); + // Restart the emulator with the last played game + StartEmulator(lastGamePath); } +#endif diff --git a/src/qt_gui/main_window.h b/src/qt_gui/main_window.h index 69d5d8800..f3cbe6b6d 100644 --- a/src/qt_gui/main_window.h +++ b/src/qt_gui/main_window.h @@ -67,7 +67,10 @@ private: void SetUiIcons(bool isWhite); void InstallPkg(); void BootGame(); +#ifdef ENABLE_QT_GUI QString getLastEbootPath(); + std::filesystem::path lastGamePath; +#endif void AddRecentFiles(QString filePath); void LoadTranslation(); void PlayBackgroundMusic();