Skip to content

Do not try to create the browser before init#519

Open
hoshinolina wants to merge 1 commit intoobsproject:masterfrom
hoshinolina:fix-init-race
Open

Do not try to create the browser before init#519
hoshinolina wants to merge 1 commit intoobsproject:masterfrom
hoshinolina:fix-init-race

Conversation

@hoshinolina
Copy link
Copy Markdown
Contributor

Description

Should fix the random asserts on startup (not related to the recent consistent startup failures), I think.

Motivation and Context

Fixes a race.

How Has This Been Tested?

Quick smoke test.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@WizardCM WizardCM added the Bug Fix Non-breaking change which fixes an issue label Apr 14, 2026
@PatTheMav
Copy link
Copy Markdown
Member

What's the actual root cause of the race? At first glance the "browser manager thread" seems like a culprit, because it decouples the actual initialisation of CEF from the main thread on Windows and Linux (but not on macOS), so CEF will only be initialised "eventually".

On macOS BrowserInit always finishes before obs_browser_initialize returns, so I guess we don't face the same issue there?

@hoshinolina
Copy link
Copy Markdown
Contributor Author

hoshinolina commented Apr 27, 2026 via email

Copy link
Copy Markdown
Member

@PatTheMav PatTheMav left a comment

Choose a reason for hiding this comment

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

Annoying that it's necessary, but seems like the most elegant fix for this race condition.

Please amend the commit description per our contribution guidelines to explain the "why" of the fix (explaining the race condition, it's root cause, and why this fixes it).

CEF is initialized in a browser manager thread on Windows and Linux,
which happens asynchronously. The graphics tick function may be
called before CEF initialization completes, which leads to
asserts and other issues. Ensure this does not happen by checking
for CEF init completion.
@hoshinolina
Copy link
Copy Markdown
Contributor Author

Done.

@RytoEX RytoEX requested a review from PatTheMav April 29, 2026 17:18
@RytoEX RytoEX self-assigned this Apr 29, 2026
Comment thread obs-browser-source.cpp
Comment on lines +553 to +554
if (os_event_try(cef_started_event) != 0)
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (os_event_try(cef_started_event) != 0)
return;
if (os_event_try(cef_started_event) != 0) {
return;
}

Sorry, should've picked up on this in my earlier preview. Per our code style guidelines, except for C code, we prefer all conditional and loop blocks to be explicitly enclosed with curlies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean... sure but... nothing else in the file does this, including the rest of the function.

I think if this is desired, someone should add InsertBraces: true to .clang-format and fix the whole codebase. Enforcing things like this in review is essentially a waste of everyone's time when clang-format can do it for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix Non-breaking change which fixes an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants