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();