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

shared/bpm: Fixed crash when using Stream Delay #11291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lexano-ivs
Copy link
Contributor

Description

While testing BPM in the Twitch Enhanced Broadcasting beta build an issue was uncovered where OBS Studio will crash due to an uninitialized mutex in the new BPM code. This crash only happens if:

  • The stream delay feature is enabled
  • The user starts streaming and stops the stream before it ever started streaming

With the official OBS Studio, the stream delay feature is not compatible with enhanced broadcasting and will be disabled if the streamer attempts to use stream delay, so there is currently no chance of running into this issue. However, once stream delay compatibility with enhanced broadcasting is upstreamed, the crash will occur in the case specified above, so best to eliminate it ahead of time.

The fix is very simple. Simply ensure the mutex is initialized once from either bpm_inject() or bpm_destroy(), instead of relying on bpm_inject() to always be called first.

Motivation and Context

This is a bug fix for a very specific case that will cause OBS Studio to crash.

How Has This Been Tested?

Tested locally with the enhanced broadcasting beta build (Twitch Enhanced Broadcasting). It is very easy to reproduce and the fix works in all iterations I've tried.

Types of changes

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

Checklist:

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

Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

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

The correct commit message prefix is shared/bpm: .

@WizardCM WizardCM added the Bug Fix Non-breaking change which fixes an issue label Sep 18, 2024
BPM initialization occurs with the first call to the
`bpm_inject()` callback function. When Stream Delay is
active, there is a case where the first call might never
happen, specifically if a user stops the stream with the
discard delay option before streaming begins. In such a
case OBS will crash due to an uninitialized mutex being
referenced in `bpm_destroy()`.

Use `pthread_once()` in both the `bpm_inject()` callback
and `bpm_destroy()` to ensure BPM initialization has occurred.
@lexano-ivs lexano-ivs changed the title BPM: Fix a crash when using Stream Delay shared/bpm: Fixed crash when using Stream Delay Sep 19, 2024
@lexano-ivs
Copy link
Contributor Author

The correct commit message prefix is shared/bpm: .

Forgot about that, sorry. Just fixed it and pushed.

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.

3 participants