From a67b3e25f9c2886dbc46c72281ab3c0eeda8de13 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Mon, 10 Mar 2008 14:18:45 +0000 Subject: [PATCH] FIX GUI bug related to COM and multi-threading git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@461 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/win32/DirectSound.cpp | 7 ------- src/win32/Directories.cpp | 1 - src/win32/VBA.cpp | 7 +++++++ src/win32/XAudio2.cpp | 26 +++++++++++++++----------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/win32/DirectSound.cpp b/src/win32/DirectSound.cpp index 5ad5067b..6b9b74fb 100644 --- a/src/win32/DirectSound.cpp +++ b/src/win32/DirectSound.cpp @@ -62,11 +62,6 @@ public: DirectSound::DirectSound() { - if( S_OK != CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) { - systemMessage( IDS_COM_FAILURE, NULL ); - return; - } - pDirectSound = NULL; dsbPrimary = NULL; dsbSecondary = NULL; @@ -103,8 +98,6 @@ DirectSound::~DirectSound() pDirectSound->Release(); pDirectSound = NULL; } - - CoUninitialize(); } diff --git a/src/win32/Directories.cpp b/src/win32/Directories.cpp index bdfde831..8b05e453 100644 --- a/src/win32/Directories.cpp +++ b/src/win32/Directories.cpp @@ -271,7 +271,6 @@ CString Directories::browseForDir(CString title) bi.lpfn = browseCallbackProc; bi.lParam = (LPARAM)(LPCTSTR)initialFolderDir; - CoInitialize( NULL ); // required by BIF_USENEWUI pidl = SHBrowseForFolder(&bi); if(pidl) { diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 7b1e3a7c..1acc4fea 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -219,6 +219,11 @@ BEGIN_MESSAGE_MAP(VBA, CWinApp) VBA::VBA() { + // COINIT_MULTITHREADED is not supported by SHBrowseForFolder with BIF_USENEWUI + // OpenAL also causes trouble when COINIT_MULTITHREADED is used + if( S_OK != CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ) ) { + systemMessage( IDS_COM_FAILURE, NULL ); + } mode320Available = false; mode640Available = false; mode800Available = false; @@ -419,6 +424,8 @@ VBA::~VBA() free( oalDevice ); } #endif + + CoUninitialize(); } ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win32/XAudio2.cpp b/src/win32/XAudio2.cpp index a95df28f..0b4f9f82 100644 --- a/src/win32/XAudio2.cpp +++ b/src/win32/XAudio2.cpp @@ -45,10 +45,22 @@ class XAudio2_BufferNotify : public IXAudio2VoiceCallback public: HANDLE hBufferEndEvent; - XAudio2_BufferNotify() { hBufferEndEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); } - ~XAudio2_BufferNotify() { CloseHandle( hBufferEndEvent ); } + XAudio2_BufferNotify() { + hBufferEndEvent = NULL; + hBufferEndEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + ASSERT( hBufferEndEvent != NULL ); + } + + ~XAudio2_BufferNotify() { + CloseHandle( hBufferEndEvent ); + hBufferEndEvent = NULL; + } + + STDMETHOD_( void, OnBufferEnd ) ( void *pBufferContext ) { + ASSERT( hBufferEndEvent != NULL ); + SetEvent( hBufferEndEvent ); + } - STDMETHOD_( void, OnBufferEnd ) ( void *pBufferContext ) { SetEvent( hBufferEndEvent ); } // dummies: STDMETHOD_( void, OnVoiceProcessingPassStart ) () {} @@ -115,12 +127,6 @@ XAudio2_Output::XAudio2_Output() sVoice = NULL; ZeroMemory( &buf, sizeof( buf ) ); ZeroMemory( &vState, sizeof( vState ) ); - - if( S_OK != CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) { - systemMessage( IDS_COM_FAILURE, NULL ); - failed = true; - return; - } } @@ -146,8 +152,6 @@ XAudio2_Output::~XAudio2_Output() if( xaud ) { xaud->Release(); } - - CoUninitialize(); }