From 342bad84029158a92260643193427af24cb2b0b2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 18 Aug 2013 23:25:14 -0700 Subject: [PATCH] Fix audio crash on shutdown, log thread names more. --- Common/ConsoleListener.cpp | 2 ++ Windows/DSoundStream.cpp | 33 ++++++++++++++++++++++----------- Windows/EmuThread.cpp | 1 + 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Common/ConsoleListener.cpp b/Common/ConsoleListener.cpp index d3f27aa413..61fba341a2 100644 --- a/Common/ConsoleListener.cpp +++ b/Common/ConsoleListener.cpp @@ -27,6 +27,7 @@ #include #endif +#include "thread/threadutil.h" #include "Common.h" #include "LogManager.h" // Common #include "ConsoleListener.h" // Common @@ -248,6 +249,7 @@ COORD ConsoleListener::GetCoordinates(int BytesRead, int BufferWidth) unsigned int WINAPI ConsoleListener::RunThread(void *lpParam) { + setCurrentThreadName("ConsoleThread"); ConsoleListener *consoleLog = (ConsoleListener *)lpParam; consoleLog->LogWriterThread(); return 0; diff --git a/Windows/DSoundStream.cpp b/Windows/DSoundStream.cpp index 9dbfafdf76..20ebde10ad 100644 --- a/Windows/DSoundStream.cpp +++ b/Windows/DSoundStream.cpp @@ -1,3 +1,4 @@ +#include "native/thread/threadutil.h" #include "Common/CommonWindows.h" #include @@ -112,6 +113,7 @@ namespace DSound unsigned int WINAPI soundThread(void *) { + setCurrentThreadName("DSoundThread"); currentPos = 0; lastPos = 0; //writeDataToBuffer(0,realtimeBuffer,bufferSize); @@ -190,18 +192,27 @@ namespace DSound void DSound_StopSound() { - threadData=1; - WaitForSingleObject(hThread,1000); - CloseHandle(hThread); - /* - while (threadData!=2) - ;*/ - if (dsBuffer != NULL) - dsBuffer->Release(); - if (ds != NULL) - ds->Release(); + if (threadData == 0) + threadData = 1; - CloseHandle(soundSyncEvent); + if (hThread != NULL) + { + WaitForSingleObject(hThread, 1000); + CloseHandle(hThread); + } + + if (threadData == 2) + { + if (dsBuffer != NULL) + dsBuffer->Release(); + dsBuffer = NULL; + if (ds != NULL) + ds->Release(); + ds = NULL; + } + + if (soundSyncEvent != NULL) + CloseHandle(soundSyncEvent); soundSyncEvent = NULL; } diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 515075aacb..5a9d9d96a4 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -139,6 +139,7 @@ shutdown: _InterlockedExchange(&emuThreadReady, THREAD_SHUTDOWN); NativeShutdownGraphics(); + host->ShutdownSound(); host = nativeHost; NativeShutdown(); host = oldHost;