Skip to content

Commit

Permalink
windows: Fix RoInitialize() failure after a CoInitializeEx() call usi…
Browse files Browse the repository at this point in the history
…ng apartment threading

This mirrors the same codepath in WIN_CoInitialize() which handles STA and MTA.
  • Loading branch information
cgutman authored and slouken committed Apr 21, 2022
1 parent 923cb44 commit 8982d9f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/core/windows/SDL_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,19 @@ WIN_RoInitialize(void)
typedef HRESULT (WINAPI *RoInitialize_t)(RO_INIT_TYPE initType);
RoInitialize_t RoInitializeFunc = (RoInitialize_t)WIN_LoadComBaseFunction("RoInitialize");
if (RoInitializeFunc) {
return RoInitializeFunc(RO_INIT_MULTITHREADED);
/* RO_INIT_SINGLETHREADED is equivalent to COINIT_APARTMENTTHREADED */
HRESULT hr = RoInitializeFunc(RO_INIT_SINGLETHREADED);
if (hr == RPC_E_CHANGED_MODE) {
hr = RoInitializeFunc(RO_INIT_MULTITHREADED);
}

/* S_FALSE means success, but someone else already initialized. */
/* You still need to call RoUninitialize in this case! */
if (hr == S_FALSE) {
return S_OK;
}

return hr;
} else {
return E_NOINTERFACE;
}
Expand Down

0 comments on commit 8982d9f

Please sign in to comment.