From e3e561da3fd2fca66b2d09ba6ed418eb4e0029b1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 31 Oct 2024 22:51:18 +0100 Subject: [PATCH] lock framebuffer stuff to prevent conflicts when reiniting the core or changing the renderer --- src/frontend/qt_sdl/EmuInstance.cpp | 2 ++ src/frontend/qt_sdl/EmuInstance.h | 2 ++ src/frontend/qt_sdl/EmuThread.cpp | 2 ++ src/frontend/qt_sdl/Screen.cpp | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 9114a141..f4092b61 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -1340,6 +1340,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB args = &(*dsiargs); } + renderLock.lock(); if ((!nds) || (consoleType != nds->ConsoleType)) { NDS::Current = nullptr; @@ -1387,6 +1388,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB dsi->EjectGBACart(); } } + renderLock.unlock(); return true; } diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index 9ab12d93..33e5fd95 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -150,6 +150,8 @@ public: void touchScreen(int x, int y); void releaseScreen(); + QMutex renderLock; + private: static int lastSep(const std::string& path); std::string getAssetPath(bool gba, const std::string& configpath, const std::string& ext, const std::string& file); diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index 7e1b040c..6417fa69 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -231,6 +231,7 @@ void EmuThread::run() // update render settings if needed if (videoSettingsDirty) { + emuInstance->renderLock.lock(); if (useOpenGL) { emuInstance->setVSyncGL(true); @@ -246,6 +247,7 @@ void EmuThread::run() updateRenderer(); videoSettingsDirty = false; + emuInstance->renderLock.unlock(); } // process input and hotkeys diff --git a/src/frontend/qt_sdl/Screen.cpp b/src/frontend/qt_sdl/Screen.cpp index 3eb37183..a1048018 100644 --- a/src/frontend/qt_sdl/Screen.cpp +++ b/src/frontend/qt_sdl/Screen.cpp @@ -779,6 +779,7 @@ void ScreenPanelNative::paintEvent(QPaintEvent* event) if (emuThread->emuIsActive()) { + emuInstance->renderLock.lock(); auto nds = emuInstance->getNDS(); assert(nds != nullptr); @@ -801,6 +802,7 @@ void ScreenPanelNative::paintEvent(QPaintEvent* event) painter.setTransform(screenTrans[i]); painter.drawImage(screenrc, screen[screenKind[i]]); } + emuInstance->renderLock.unlock(); } osdUpdate();