diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index d0789156f4..24a5ba5b74 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -247,6 +247,7 @@ void GLRenderManager::StopThread() { GLRRenderThreadTask exitTask{}; exitTask.runType = GLRRunType::EXIT; renderThreadQueue_.push(exitTask); + pushCondVar_.notify_one(); } else { WARN_LOG(G3D, "GL submission thread was already paused."); } diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index 0f7760f63e..7516b22218 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -437,7 +437,7 @@ public: // We pass in width/height here even though it's not strictly needed until we support glTextureStorage // and then we'll also need formats and stuff. GLRTexture *CreateTexture(GLenum target, int width, int height, int depth, int numMips) { - GLRInitStep step{ GLRInitStepType::CREATE_TEXTURE }; + GLRInitStep step { GLRInitStepType::CREATE_TEXTURE }; step.create_texture.texture = new GLRTexture(caps_, width, height, depth, numMips); step.create_texture.texture->target = target; initSteps_.push_back(step); diff --git a/Core/Core.cpp b/Core/Core.cpp index d71887acea..599d5b7dfb 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -328,14 +328,14 @@ void Core_ProcessStepping() { // Many platforms, like Android, do not call this function but handle things on their own. // Instead they simply call NativeRender and NativeUpdate directly. -void Core_Run(GraphicsContext *ctx) { +bool Core_Run(GraphicsContext *ctx) { host->UpdateDisassembly(); while (true) { if (GetUIState() != UISTATE_INGAME) { Core_StateProcessed(); if (GetUIState() == UISTATE_EXIT) { UpdateRunLoop(); - return; + return false; } Core_RunLoop(ctx); continue; @@ -348,7 +348,7 @@ void Core_Run(GraphicsContext *ctx) { Core_RunLoop(ctx); if (coreState == CORE_POWERDOWN) { Core_StateProcessed(); - return; + return true; } break; @@ -359,10 +359,10 @@ void Core_Run(GraphicsContext *ctx) { // Exit loop!! Core_StateProcessed(); - return; + return true; case CORE_NEXTFRAME: - return; + return true; } } } diff --git a/Core/Core.h b/Core/Core.h index 6fb372311c..333dbd1b4a 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -27,8 +27,10 @@ class GraphicsContext; // called from emu thread void UpdateRunLoop(); -void Core_Run(GraphicsContext *ctx); +// Returns false when an UI exit state is detected. +bool Core_Run(GraphicsContext *ctx); void Core_Stop(); + // For platforms that don't call Core_Run void Core_SetGraphicsContext(GraphicsContext *ctx); diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 823208c851..c28b59279e 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -82,7 +82,9 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) { // This way they can load a new game. if (!Core_IsActive()) UpdateUIState(UISTATE_MENU); - Core_Run(g_graphicsContext); + if (!Core_Run(g_graphicsContext)) { + emuThreadState = (int)EmuThreadState::QUIT_REQUESTED; + } } emuThreadState = (int)EmuThreadState::STOPPED; @@ -99,12 +101,14 @@ static void EmuThreadStart(GraphicsContext *graphicsContext) { } static void EmuThreadStop() { - emuThreadState = (int)EmuThreadState::QUIT_REQUESTED; + if (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED && + emuThreadState != (int)EmuThreadState::STOPPED) { + emuThreadState = (int)EmuThreadState::QUIT_REQUESTED; + } } static void EmuThreadJoin() { emuThread.join(); - emuThread = std::thread(); INFO_LOG(SYSTEM, "EmuThreadJoin - joined"); }