Skip to content

Cubeb: Initialize COM on init#13364

Closed
JordanTheToaster wants to merge 1 commit intoPCSX2:masterfrom
JordanTheToaster:cobeb
Closed

Cubeb: Initialize COM on init#13364
JordanTheToaster wants to merge 1 commit intoPCSX2:masterfrom
JordanTheToaster:cobeb

Conversation

@JordanTheToaster
Copy link
Copy Markdown
Member

Description of Changes

Initializes COM on cubeb init.

Rationale behind Changes

Updating to SDL 3.2.24 exposed a bug with our cubeb implementation as we didn't initialise COM causing the GS dump runner to crash.

"Cubed's WASAPI doesn't initialise COM on init (it's documented that we should do that)
This is normally fine as we call CoInitializeEx in VMManager::Internal::CPUThreadInitialize()

GSRunner, however, calls CPUThreadInitialize() in the main thread, and then starts a different thread to run the VM on
As COM needs to be initialised per thread, that meant the VM thread didn't have COM initialised.

As it happened, SDL was initialising COM when setting up Windows.Gaming.Input (and thus hiding the above issue)
Between the 2 SDL versions, the default value for the hint SDL_JOYSTICK_WGI was switched from true to false
Thus, SDL stopped needing to initialising COM, exposing our bug"

Suggested Testing Steps

Test to see if the dump runner works correctly and audio on Windows works as expected.

Did you use AI to help find, test, or implement this issue or feature?

No

Comment thread pcsx2/Host/CubebAudioStream.cpp Outdated
@TheLastRar
Copy link
Copy Markdown
Contributor

We should probably call CoUninitialize() if cubeb_init fails but initialising COM succeeded.

And also in DestroyContextAndStream() if m_context is not null

@TheTechnician27
Copy link
Copy Markdown
Contributor

@TheLastRar How does this interact, if at all, with #13366?

@TheLastRar
Copy link
Copy Markdown
Contributor

No interaction, but I am testing an alternative to this pr

@CookiePLMonster
Copy link
Copy Markdown
Contributor

CookiePLMonster commented Oct 14, 2025

We should probably call CoUninitialize() if cubeb_init fails but initialising COM succeeded.

And also in DestroyContextAndStream() if m_context is not null

wil::unique_couninitialize_call can be used for that, just careful with using wil::CoInitializeEx as it considers "already initialized" an error. EyeToy for example uses it.

@JordanTheToaster
Copy link
Copy Markdown
Member Author

Superseded by #13393

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.

5 participants