Skip to content

Windows: COM initialization fixes#13393

Merged
F0bes merged 3 commits intoPCSX2:masterfrom
CookiePLMonster:cubeb-coinitialize
Oct 22, 2025
Merged

Windows: COM initialization fixes#13393
F0bes merged 3 commits intoPCSX2:masterfrom
CookiePLMonster:cubeb-coinitialize

Conversation

@CookiePLMonster
Copy link
Copy Markdown
Contributor

Description of Changes

Cleans up COM initialization for the sake of Cubeb and EyeToy. The following changes were made:

  1. On Windows, all uses of Cubeb in the USB mic and SPU2 outputs now explicitly request MTA COM model.
  2. As Qt initializes the main thread to STA, Cubeb device enumeration has been moved to the emulation thread. Cubeb initialized fine in STA, but it's against the docs, so maybe it would break sometime in the future.
  3. COM initialization for EyeToy was cleaned up and a bug was fixed - EyeToy that is enabled in options but not started by the game would call CoUninitialize on edit without a corresponding CoInitializeEx call beforehand, breaking the COM state.

Replaces #13364.

Rationale behind Changes

Code correctness.

Suggested Testing Steps

  1. Ensure that Cubeb devices enumerate and audio works (on Windows).
  2. Ensure that USB microphones enumerate and work fine.
  3. Ensure that EyeToy starts.

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

No.

@CookiePLMonster CookiePLMonster changed the title Cubeb coinitialize Windows: COM initialization fixes Oct 14, 2025
@CookiePLMonster CookiePLMonster marked this pull request as draft October 15, 2025 07:59
@CookiePLMonster CookiePLMonster marked this pull request as ready for review October 15, 2025 08:51
Copy link
Copy Markdown
Member

@JordanTheToaster JordanTheToaster left a comment

Choose a reason for hiding this comment

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

Cubeb and eye toy still functions correctly on Windows.

Copy link
Copy Markdown
Contributor

@TheLastRar TheLastRar left a comment

Choose a reason for hiding this comment

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

Is the global namespace :: needed for CoInitializeEx?

As for cubeb, you are allowing STA (despite the pr description), what made you drop the MTA changes?

@CookiePLMonster
Copy link
Copy Markdown
Contributor Author

Is the global namespace :: needed for CoInitializeEx?

No, just a habit.

As for cubeb, you are allowing STA (despite the pr description), what made you drop the MTA changes?

  1. Delegating from the UI to emuthread could theoretically result in deadlocks (when blocking), so it's not a great idea.
  2. I only allow STA for enumerating devices, and that doesn't create COM objects across threads. Creating Cubeb streams does, and that's why the main CubebAudioStream still wants MTA.

Comment thread pcsx2/USB/usb-mic/audiodev-cubeb.cpp
@TheLastRar
Copy link
Copy Markdown
Contributor

Is the global namespace :: needed for CoInitializeEx?

No, just a habit.

I would personally omit it if it was unneeded, which would align with other uses of Windows API functions.

  1. I only allow STA for enumerating devices, and that doesn't create COM objects across threads. Creating Cubeb streams does, and that's why the main CubebAudioStream still wants MTA.

Given Cubeb's recommendation, can a comment be added with the above.

Also, the usb mic can share the cubed instance between the UI and CPU thread, Is this okay given the different apartment types between the two?

@CookiePLMonster
Copy link
Copy Markdown
Contributor Author

I would personally omit it if it was unneeded, which would align with other uses of Windows API functions.

I'll change it.

Also, the usb mic can share the cubed instance between the UI and CPU thread, Is this okay given the different apartment types between the two?

As far as I can tell, UI could share the instance from the CPU thread (one that was initialized in MTA), but not vice versa, so it should be fine. Even though it may not look like this, the behaviour of USB mic is effectively unchanged to what we're doing now, and no one ever complained about enumerations failing.

If the EyeToy camera was enabled in the settings, but not enabled
by the game, it would call CoUninitialize without having called
CoInitializeEx first.
Copy link
Copy Markdown
Contributor

@TheLastRar TheLastRar left a comment

Choose a reason for hiding this comment

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

Changes look good, but haven't personally tested

Copy link
Copy Markdown
Contributor

@kamfretoz kamfretoz left a comment

Choose a reason for hiding this comment

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

Audio device selection and others still works.

Copy link
Copy Markdown
Member

@F0bes F0bes left a comment

Choose a reason for hiding this comment

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

I think it LGTM

@F0bes F0bes merged commit 3cf21e0 into PCSX2:master Oct 22, 2025
12 checks passed
@CookiePLMonster CookiePLMonster deleted the cubeb-coinitialize branch October 22, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants