diff --git a/Common/GraphicsContext.h b/Common/GraphicsContext.h index 66afcd94da..5dfec7f6d9 100644 --- a/Common/GraphicsContext.h +++ b/Common/GraphicsContext.h @@ -32,6 +32,7 @@ public: virtual void ThreadStart() {} virtual bool ThreadFrame() { return true; } virtual void ThreadEnd() {} + virtual void StopThread() {} virtual Draw::DrawContext *GetDrawContext() = 0; }; diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 5b9d1faca5..4e18eb1f53 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -86,6 +86,9 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) { emuThreadState = (int)EmuThreadState::STOPPED; NativeShutdownGraphics(); + + // Ask the main thread to stop. This prevents a hang on a race condition. + graphicsContext->StopThread(); } static void EmuThreadStart(GraphicsContext *graphicsContext) { diff --git a/Windows/GPU/WindowsGLContext.cpp b/Windows/GPU/WindowsGLContext.cpp index 7962d3a817..b5dfc831d0 100644 --- a/Windows/GPU/WindowsGLContext.cpp +++ b/Windows/GPU/WindowsGLContext.cpp @@ -432,3 +432,8 @@ bool WindowsGLContext::ThreadFrame() { void WindowsGLContext::ThreadEnd() { renderManager_->ThreadEnd(); } + +void WindowsGLContext::StopThread() { + renderManager_->WaitUntilQueueIdle(); + renderManager_->StopThread(); +} diff --git a/Windows/GPU/WindowsGLContext.h b/Windows/GPU/WindowsGLContext.h index 38c9494947..1303aece79 100644 --- a/Windows/GPU/WindowsGLContext.h +++ b/Windows/GPU/WindowsGLContext.h @@ -29,6 +29,7 @@ public: void ThreadStart() override; void ThreadEnd() override; bool ThreadFrame() override; + void StopThread() override; Draw::DrawContext *GetDrawContext() override { return draw_; }