Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
8036ac37
Commit
8036ac37
authored
Jul 14, 2024
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WASAPI: Fix a crash when changing devices.
parent
fc45d8ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
miniaudio.h
miniaudio.h
+17
-2
No files found.
miniaudio.h
View file @
8036ac37
...
@@ -21541,8 +21541,23 @@ static ma_result ma_context_get_MMDevice__wasapi(ma_context* pContext, ma_device
...
@@ -21541,8 +21541,23 @@ static ma_result ma_context_get_MMDevice__wasapi(ma_context* pContext, ma_device
MA_ASSERT(pContext != NULL);
MA_ASSERT(pContext != NULL);
MA_ASSERT(ppMMDevice != NULL);
MA_ASSERT(ppMMDevice != NULL);
hr = ma_CoCreateInstance(pContext, &MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
/*
if (FAILED(hr)) {
This weird COM init/uninit here is a hack to work around a crash when changing devices. What is happening is
WASAPI fires a callback from another thread when the device is changed. It's from that thread where this
function is getting called. What I'm suspecting is that the other thread is not initializing COM which in turn
results in CoCreateInstance() failing.
The community has reported that this seems to fix the crash. There are future plans to move all WASAPI operation
over to a single thread to make everything safer, but in the meantime while we wait for that to come online I'm
happy enough to use this hack instead.
*/
ma_CoInitializeEx(pContext, NULL, MA_COINIT_VALUE);
{
hr = ma_CoCreateInstance(pContext, &MA_CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &MA_IID_IMMDeviceEnumerator, (void**)&pDeviceEnumerator);
}
ma_CoUninitialize(pContext);
if (FAILED(hr)) { /* <-- This is checking the call above to ma_CoCreateInstance(). */
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create IMMDeviceEnumerator.\n");
ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to create IMMDeviceEnumerator.\n");
return ma_result_from_HRESULT(hr);
return ma_result_from_HRESULT(hr);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment