From 11e417f55a7c078167e36117edb41533479af458 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 28 Jul 2009 05:12:23 +0000 Subject: [PATCH] win32: safer threading logic in shutdown sequence --- desmume/src/windows/main.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 4a433320c..441a86338 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -827,6 +827,7 @@ volatile int currDisplayBuffer=-1; volatile int newestDisplayBuffer=-2; GMutex *display_mutex = NULL; GThread *display_thread = NULL; +volatile bool display_die = false; static void DoDisplay_DrawHud() { @@ -901,11 +902,18 @@ void displayProc() void displayThread(void*) { for(;;) { + if(display_die) return; displayProc(); Sleep(10); //don't be greedy and use a whole cpu core, but leave room for 60fps } } +void KillDisplay() +{ + display_die = true; + g_thread_join(display_thread); +} + void Display() { CallRegisteredLuaFunctions(LUACALL_AFTEREMULATIONGUI); @@ -1185,10 +1193,6 @@ fps=0; Sleep(100); } - if (lpDDClipPrimary!=NULL) IDirectDraw7_Release(lpDDClipPrimary); - if (lpPrimarySurface != NULL) IDirectDraw7_Release(lpPrimarySurface); - if (lpBackSurface != NULL) IDirectDraw7_Release(lpBackSurface); - if (lpDDraw != NULL) IDirectDraw7_Release(lpDDraw); return 1; } @@ -1890,6 +1894,13 @@ int _main() delete MainWindow; + KillDisplay(); + + if (lpDDClipPrimary!=NULL) IDirectDraw7_Release(lpDDClipPrimary); + if (lpPrimarySurface != NULL) IDirectDraw7_Release(lpPrimarySurface); + if (lpBackSurface != NULL) IDirectDraw7_Release(lpBackSurface); + if (lpDDraw != NULL) IDirectDraw7_Release(lpDDraw); + return 0; }