Skip to content

libobs: Make sure all code paths leave context - #13375

Merged
RytoEX merged 1 commit into
obsproject:masterfrom
suogesi:fix/13366
Sep 18, 2026
Merged

RytoEX merged 1 commit into
obsproject:masterfrom
suogesi:fix/13366

Conversation

@suogesi

@suogesi suogesi commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Description

Not calling gs_leave_context after gs_enter_context can cause a lock leak. This PR makes sure all code paths in obs_init_video_mix from libobs/obs.c will do this.

Motivation and Context

#13366

This is NOT a complete fix of this issue. OBS should show error messages to remind users not to write such resolution because GPU cannot process it.

This PR makes "Stop Recording" work but the output is not as expected. (i.e., if you write "1920x1079" into Settings > Output (Advanced) > Recording > Rescale Output, you won't get a 1920x1079 video. Instead, you get a default resolution.)

How Has This Been Tested?

  1. Select "NVIDIA NVENC H.264" at Settings > Output (Advanced) > Recording > Video Encoder.
  2. Select "Bilinear" at Settings > Output (Advanced) > Recording > Rescale Output.
  3. Write "1920x1079" into Settings > Output (Advanced) > Recording > Rescale Output.
  4. Click "Start Recording".
  5. Click "Stop Recording".
  6. Video saved instead of keeping "Stopping Recording...".

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.

Comment thread libobs/obs.c Outdated
@WizardCM WizardCM added the kind/bug Categorizes issue or PR as related to a bug. label May 1, 2026
@github-project-automation github-project-automation Bot moved this to Ready For Review in 33.0 Release Tracker Jul 6, 2026
@Warchamp7 Warchamp7 added this to the OBS Studio 33.0 milestone Jul 6, 2026
@Warchamp7

Copy link
Copy Markdown
Member

This will need to be properly rebased and squashed instead of the merge commit.

@Warchamp7 Warchamp7 moved this from Ready For Review to Requires Changes in 33.0 Release Tracker Aug 7, 2026
@Warchamp7
Warchamp7 requested a review from Lain-B August 21, 2026 21:52

@PatTheMav PatTheMav left a comment

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.

Almost a poster boy example for the benefits of the defer statement, which would allow us to write:

defer {
    gs_leave_context();
}

if (video-gpu_conversion && !obs_init_gpu_conversion(video)) {
    return OBS_VIDEO_FAIL;
}

if (!obs_init_textures(video)) {
    return OBS_VIDEO_FAIL;
}

return OBS_VIDEO_SUCCESS;

Until we can make use of that fabled C language version, we have to use the change as suggested by the PR.

Should always call `gs_leave_context` after `gs_enter_context` or it
might cause a lock leave.

This commit makes sure all code paths will call `gs_leave_context` if
it called `gs_enter_context`.
@RytoEX
RytoEX merged commit 1bb3a4e into obsproject:master Sep 18, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Requires Changes to Merged in 33.0 Release Tracker Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug.

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

6 participants