Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsioDriverList needs a balanced call of CoInitialize/CoUninitialize #436

Open
eyeco opened this issue Sep 19, 2024 · 2 comments
Open

AsioDriverList needs a balanced call of CoInitialize/CoUninitialize #436

eyeco opened this issue Sep 19, 2024 · 2 comments

Comments

@eyeco
Copy link

eyeco commented Sep 19, 2024

AsioDriverList needs a balanced call of CoInitialize/CoUninitialize just like, e.g., RtApiAsio, RtApiDs, or RtApiWasapi. The thing is that, if the application earlier already initialized COM using multithreading, then CoInitialize( NULL ) in the constructor of AsioDriverList will fail with RPC_E_CHANGED_MODE, in which case you must NOT call CoUninitialize() in the destructor, because if you do so, you are one uninit-call ahead, which causes a fail fast exception at the final CoUninitialize() at least in my code and I wouldn't know how to prevent this. The solution is to introduce a bool flag just like in RtApiDs and other parts of the code, e.g.:

constructor code:
coInitialized_ = false; HRESULT hr = CoInitialize( NULL ); if ( !FAILED( hr ) ) coInitialized_ = true;

destructor code:
if ( coInitialized_ ) CoUninitialize(); // balanced call.

idk if additional error handlingis required if the mode is not single-threaded apartment (which it would be in my case), frankly, idk what the reason for this requirement is in the first place, but what I do know is that there is an extra call of CoUninitialize.

@garyscavone
Copy link
Contributor

I don't have access to a Windows system so it would be appreciated if you would submit a pull request with the fix.

@eyeco
Copy link
Author

eyeco commented Sep 30, 2024

#438. Let me know if this works, I'm not familiar with how pull requests work, never made one. It's really just 5 lines of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants