From b3a09791b12bb5b5b8fb8c2b9bc54e59ea8fa9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 7 Feb 2018 12:22:19 +0100 Subject: [PATCH] SDL: Fix emuthread management to exit cleanly without hanging. --- SDL/SDLMain.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index e6258fbe7d..e22036db57 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -432,6 +432,9 @@ static void EmuThreadStart(GraphicsContext *context) { static void EmuThreadStop() { emuThreadState = (int)EmuThreadState::QUIT_REQUESTED; +} + +static void EmuThreadJoin() { emuThread.join(); emuThread = std::thread(); } @@ -892,7 +895,14 @@ int main(int argc, char *argv[]) { framecount++; } - EmuThreadStop(); + if (useEmuThread) { + EmuThreadStop(); + while (emuThreadState != (int)EmuThreadState::STOPPED) { + // Need to keep eating frames to allow the EmuThread to exit correctly. + graphicsContext->ThreadFrame(); + } + EmuThreadJoin(); + } delete joystick; @@ -902,6 +912,7 @@ int main(int argc, char *argv[]) { graphicsContext->Shutdown(); graphicsContext->ThreadEnd(); graphicsContext->ShutdownFromRenderThread(); + NativeShutdown(); delete graphicsContext;