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

windows: Fix RoInitialize() failure after a CoInitializeEx() call using apartment threading #5554

Merged
merged 3 commits into from
Apr 21, 2022

Conversation

cgutman
Copy link
Collaborator

@cgutman cgutman commented Apr 19, 2022

Description

This fixes #5552 by trying RoInitialize() with both RO_INIT_SINGLETHREADED and RO_INIT_MULTITHREADED to avoid failing if WIN_CoInitialize() is called first. I also adjusted the code to mirror WIN_CoInitialize() more closely.

According to contextfree/winrt-rust#62 (comment), RO_INIT_SINGLETHREADED is equivalent to COINIT_APARTMENTTHREADED.

Existing Issue(s)

Fixes #5552

@cgutman
Copy link
Collaborator Author

cgutman commented Apr 19, 2022

Ugh, this reintroduces #5270. Maybe it just stopped happening because WGI itself was broken...

…ng apartment threading

This mirrors the same codepath in WIN_CoInitialize() which handles STA and MTA.
CoIncrementMTAUsage_t CoIncrementMTAUsageFunc = (CoIncrementMTAUsage_t)WIN_LoadComBaseFunction("CoIncrementMTAUsage");
if (CoIncrementMTAUsageFunc) {
if (FAILED(CoIncrementMTAUsageFunc(&cookie))) {
return SDL_SetError("CoIncrementMTAUsage() failed");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to call WIN_RoUninitialize() in all the error cases in this function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WGI_JoystickQuit() will still call WIN_RoUninitialize() even if we fail initialization here.

However, it does look like there's a bug here if WIN_RoInitialize() itself fails. Calling WIN_RoUninitialize() in that case is wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed 7325953 to fix that

@slouken slouken merged commit 145824f into libsdl-org:main Apr 21, 2022
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

Successfully merging this pull request may close these issues.

WGI initialization fails on Win32
2 participants