@@ -162,6 +162,9 @@ void DefaultDeviceChangeThread(void* data) {
162162 static uint64 nextCheck = 0 ;
163163 const uint64 waitTime = 5000 ;
164164 while (1 ) {
165+ if (soundSystemLocal.systemClosing ) {
166+ break ;
167+ }
165168 int now = Sys_Milliseconds ();
166169 if (now >= nextCheck) {
167170#if defined(_MSC_VER) && defined(USE_XAUDIO2)
@@ -233,14 +236,15 @@ void idSoundSystemLocal::Init()
233236 idLib::Printf (" Creating Default Device Detection Thread\n " );
234237#if defined(_MSC_VER) && defined(USE_XAUDIO2)
235238 if (useXAudio) {
236- Sys_CreateThread ((xthread_t )DefaultDeviceChangeThread, ((idSoundHardware_XAudio2*)hardware)->GetSelectedDevice (), THREAD_LOWEST, " Default Audio Device Change Listener" , CORE_ANY);
239+ threadHandle = Sys_CreateThread ((xthread_t )DefaultDeviceChangeThread, ((idSoundHardware_XAudio2*)hardware)->GetSelectedDevice (), THREAD_LOWEST, " Default Audio Device Change Listener" , CORE_ANY);
237240 }
238241 else
239242#endif
240243 {
241- Sys_CreateThread ((xthread_t )DefaultDeviceChangeThread, this ->GetInternal (), THREAD_LOWEST, " Default Audio Device Change Listener" , CORE_ANY);
244+ threadHandle = Sys_CreateThread ((xthread_t )DefaultDeviceChangeThread, this ->GetInternal (), THREAD_LOWEST, " Default Audio Device Change Listener" , CORE_ANY);
242245 }
243246 initOnce = true ;
247+ systemClosing = false ;
244248 }
245249}
246250
@@ -296,6 +300,8 @@ idSoundSystemLocal::Shutdown
296300*/
297301void idSoundSystemLocal::Shutdown ()
298302{
303+ systemClosing = true ;
304+ Sys_DestroyThread (threadHandle);
299305 hardware->Shutdown ();
300306 // EAX or not, the list needs to be cleared
301307 EFXDatabase.Clear ();
0 commit comments