From dbd75f8ae406fdd87b6546fdac78448b742f4cff Mon Sep 17 00:00:00 2001 From: RSDuck Date: Wed, 12 Oct 2022 23:28:07 +0200 Subject: [PATCH] don't segfault on closing --- src/frontend/qt_sdl/main.cpp | 42 ++++++++++++++++++------------------ src/frontend/qt_sdl/main.h | 3 +++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index af1c4911..73962aa1 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -464,15 +464,12 @@ void EmuThread::run() videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; videoSettings.GL_BetterPolygons = Config::GL_BetterPolygons; - bool hasOGL = mainWindow->hasOGL; -#ifdef OGLRENDERER_ENABLED - if (hasOGL) + if (mainWindow->hasOGL) { initOpenGL(); videoRenderer = Config::_3DRenderer; } else -#endif { videoRenderer = 0; } @@ -547,20 +544,19 @@ void EmuThread::run() // update render settings if needed if (videoSettingsDirty) { - if (hasOGL != mainWindow->hasOGL) + if (oglContext) { - hasOGL = mainWindow->hasOGL; + oglContext->SetSwapInterval(Config::ScreenVSync ? Config::ScreenVSyncInterval : 0); + videoRenderer = Config::_3DRenderer; + } #ifdef OGLRENDERER_ENABLED - if (hasOGL) - videoRenderer = Config::_3DRenderer; - else -#endif - videoRenderer = 0; - } else +#endif { - videoRenderer = hasOGL ? Config::_3DRenderer : 0; - } + videoRenderer = 0; + } + + videoRenderer = oglContext ? Config::_3DRenderer : 0; videoSettingsDirty = false; @@ -568,11 +564,6 @@ void EmuThread::run() videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; videoSettings.GL_BetterPolygons = Config::GL_BetterPolygons; - if (hasOGL) - { - oglContext->SetSwapInterval(Config::ScreenVSync ? Config::ScreenVSyncInterval : 0); - } - GPU::SetRenderSettings(videoRenderer, videoSettings); } @@ -629,7 +620,7 @@ void EmuThread::run() if (ROMManager::GBASave) ROMManager::GBASave->CheckFlush(); - if (!hasOGL) + if (!oglContext) { FrontBufferLock.lock(); FrontBuffer = GPU::FrontBuffer; @@ -752,7 +743,7 @@ void EmuThread::run() NDS::DeInit(); //Platform::LAN_DeInit(); - if (hasOGL) + if (oglContext) deinitOpenGL(); } @@ -1831,6 +1822,15 @@ MainWindow::~MainWindow() { } +void MainWindow::closeEvent(QCloseEvent* event) +{ + printf("close event\n"); + emuThread->emuPause(); + emuThread->deinitContext(); + + QMainWindow::closeEvent(event); +} + void MainWindow::createScreenPanel() { hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index fb12199a..ed015fe9 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -325,6 +326,8 @@ private slots: void onFullscreenToggled(); private: + void closeEvent(QCloseEvent* event); + QStringList currentROM; QStringList currentGBAROM; QList recentFileList;