From 51a16f823e555cafeea20f05f72fe36eec12f8e5 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 15 Jun 2008 12:59:49 +0000 Subject: [PATCH] Yet another attempt to fix #521, 'Cannot wait for thread termination' in rare cases with the DirectSound audio player. Make the playback thread detached so it will kill itself when it has run to end, instead of having to wait for it. This way it is never required to wait for the thread. When the thread has been signalled to stop it is simply abandoned and left to die for itself. Originally committed to SVN as r2201. --- aegisub/audio_player_dsound.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aegisub/audio_player_dsound.cpp b/aegisub/audio_player_dsound.cpp index 12332ac16..21fe1647a 100644 --- a/aegisub/audio_player_dsound.cpp +++ b/aegisub/audio_player_dsound.cpp @@ -276,7 +276,8 @@ void DirectSoundPlayer::Stop(bool timerToo) { if (thread) { if (thread->IsAlive()) { thread->Stop(); - thread->Wait(); + // The thread is detached so it kills/deletes itself after being stopped + //thread->Wait(); } thread = NULL; } @@ -330,7 +331,7 @@ int64_t DirectSoundPlayer::GetCurrentPosition() { ////////////////////// // Thread constructor -DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_JOINABLE) { +DirectSoundPlayerThread::DirectSoundPlayerThread(DirectSoundPlayer *par) : wxThread(wxTHREAD_DETACHED) { parent = par; stopnotify = CreateEvent(NULL, true, false, NULL); } @@ -346,6 +347,7 @@ DirectSoundPlayerThread::~DirectSoundPlayerThread() { ////////////////////// // Thread entry point wxThread::ExitCode DirectSoundPlayerThread::Entry() { + // Every thread that uses COM must initialise it CoInitialize(0); // Wake up thread every half second to fill buffer as needed @@ -388,6 +390,7 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() { parent->playing = false; parent->buffer->Stop(); + // And un-init COM since we inited it CoUninitialize(); return 0; }