summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/backends/mmdevapi.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c
index 0c2e00b0..e109b5b5 100644
--- a/Alc/backends/mmdevapi.c
+++ b/Alc/backends/mmdevapi.c
@@ -452,16 +452,16 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr)
ALuint deviceCount = 0;
MMDevApiData *data;
ALCdevice *device;
- HRESULT hr;
+ HRESULT hr, cohr;
MSG msg;
TRACE("Starting message thread\n");
- hr = CoInitialize(NULL);
- if(FAILED(hr))
+ cohr = CoInitialize(NULL);
+ if(FAILED(cohr))
{
- WARN("Failed to initialize COM: 0x%08lx\n", hr);
- req->result = hr;
+ WARN("Failed to initialize COM: 0x%08lx\n", cohr);
+ req->result = cohr;
SetEvent(req->FinishedEvt);
return 0;
}
@@ -495,10 +495,11 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr)
device = (ALCdevice*)msg.lParam;
data = device->ExtraData;
- hr = S_OK;
+ cohr = S_OK;
+ hr = E_FAIL;
if(++deviceCount == 1)
- hr = CoInitialize(NULL);
- if(SUCCEEDED(hr))
+ cohr = CoInitialize(NULL);
+ if(SUCCEEDED(cohr))
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr);
if(SUCCEEDED(hr))
{
@@ -517,6 +518,8 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr)
if(data->mmdev)
IMMDevice_Release(data->mmdev);
data->mmdev = NULL;
+ if(--deviceCount == 0 && SUCCEEDED(cohr))
+ CoUninitialize();
}
req->result = hr;