Skip to content

libobs: Apply scene item visibility changes in scenes that are only shown - #358

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/4120-preview-only-hide
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/4120-preview-only-hide

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

In Studio Mode, hiding a source that is only in the Preview scene now hides it, so "Shutdown source when not visible" fires for browser sources. Before, a source with audio (browser, media, scenes, groups) hidden there stayed "visible" forever.

  • obs_sceneitem_set_visible() does not hide an item whose source has audio at once. It queues an audio action, so the audio thread can fade the audio on a sample boundary. Those actions are applied in scene_audio_render(), and the audio thread only renders the active tree of the output channels.
  • The frontend shows the Studio Mode Preview scene with obs_source_inc_showing(): it is showing but not active. Its audio is never rendered, so the hide stayed queued and the source kept its show reference. Its hide callback never ran. Projectors of a scene and the multiview show scenes the same way. A scene that leaves the Program right after a hide (switching scenes in Studio Mode) kept the hide queued too.
  • The fix applies the pending audio actions of a scene that is not active from its video tick. Such a scene mixes no audio, so nothing is lost by applying them at once. Active scenes are unchanged, and the Program still fades on a sample boundary. Removing an item already worked, because removal is applied at once.
  1. test/cmocka: Add failing test for hiding a source only in the Studio Mode preview: test_preview_only_hide registers a source that counts its show/hide and activate/deactivate callbacks, with audio and video-only, starts core video and audio, puts a Program scene on output channel 0 and shows a Preview scene with obs_source_inc_showing(), as the frontend does. Each check waits up to 500 ms (15 video ticks). The cases are:

    • hide, show and hide again an item with audio in the Preview scene, then remove it (the steps from the report);
    • hide and show a group in the Preview scene (groups carry audio);
    • hide an item in the Program scene and switch the Program to another scene right away;
    • controls: the same toggling with a video-only source, removing a visible item with audio from the Preview scene, and hiding and showing an item with audio in the Program scene.

    Today the hidden source keeps show_refs=1 and gets no hide callback. 3 of 6 fail; the controls pass.

  2. libobs: Apply scene item visibility changes in scenes that are only shown: applies the queued actions from scene_video_tick() when the scene is not active. 6 of 6 pass.

Motivation and Context

Fixes #357 (upstream obsproject/obs-studio#4120, reported by Bobber-bob with a counter page that shows the problem). Fenrirthviti confirmed it upstream in 2021 and again on 32.0.1 in 2025; PatTheMav found that media sources are affected too and traced it to the scene item audio actions, which this fix follows.

There is no upstream PR for this. The browser-side report, obsproject/obs-browser#412, was closed in favour of the obs-studio issue.

Related merged fixes in this fork touch the same code but not this path: #242 (group active refs) and #325 (group hide transitions) cover scenes on the Program, and #250 (media stale frame) is a media source change. Their tests pass unchanged.

Why this one: "Shutdown source when not visible" is how browser overlays are reset, and Studio Mode is where people prepare the next scene. The issue has been open and confirmed since 2021.

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), on current master:

  • test_preview_only_hide: 3 of 6 cases fail at the RED commit (every time in 6 runs) and 6 of 6 pass at GREEN, under a private Xvfb with software GL, using the OpenGL module built in the tree with the installed system one masked. ctest -V shows every case run, none skipped. Repeated 20 times per lane at GREEN: same result every time.
  • Full ctest at GREEN: 116 of 116 in each lane (rebased on current master), with and without the system OpenGL module masked. Without a display, the new test's cases skip.
  • clang-format, gersemi and ci/test_registration.py are clean. The test is registered on Linux only and links only libobs (and its caption headers) and cmocka, like the other libobs scene tests.

Not tested:

  • The OBS UI and a real browser source. The test drives the same libobs calls the frontend makes (obs_source_inc_showing() for the Preview, obs_sceneitem_set_visible() for the eye icon) and checks the hide callback that the browser source's shutdown option hooks into.
  • Audio levels: a scene that is not active mixes no audio, so applying its actions early changes no sound.

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.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

…Mode preview

In Studio Mode the frontend shows the Preview scene with
obs_source_inc_showing(); only the Program is on an output channel. A
source that is only in the Preview scene must stop showing when its item
is hidden, so "Shutdown source when not visible" (browser source, media
source) can fire.

The test registers a source that counts its show/hide and
activate/deactivate callbacks, with audio (like a browser or media
source) and video-only, puts the Program scene on output channel 0 and
shows a Preview scene with obs_source_inc_showing(). Each check waits up
to 500 ms (15 video ticks).

Cases:
- hide, show and hide again an item with audio in the Preview scene,
  then remove it (the steps from the report);
- hide and show a group in the Preview scene (groups carry audio);
- hide an item in the Program scene and switch the Program to another
  scene right away, so its scene is left only in the Preview;
- controls: the same toggling with a video-only source, removing a
  visible item with audio from the Preview scene, and hiding and
  showing an item with audio in the Program scene.

On master, under xvfb (both ENABLE_RUST_LIBOBS lanes, with the built
OpenGL module and the system one masked), the three cases fail: the
hidden source keeps show_refs=1 and never gets its hide callback. The
controls pass. Without a display every case skips.

Reported upstream in obsproject/obs-studio#4120 by Bobber-bob;
confirmed by Fenrirthviti (still present in 32.0.1) and diagnosed by
PatTheMav, who traced it to the scene item audio actions.

Refs obs-rust#357.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 12, 2026 10:13
…hown

In Studio Mode, hiding a source that was only in the Preview scene never
hid it, so "Shutdown source when not visible" never shut down a browser
source. Showing or hiding an item whose source has audio (browser and
media sources, scenes, groups) is queued as an audio action, so the
audio thread can apply it on a sample boundary. The actions are applied
in scene_audio_render(), and the audio thread only renders the active
tree of the output channels.

The frontend shows the Preview scene with obs_source_inc_showing(), so
it is showing but not active, and its audio is never rendered. The hide
stayed queued, the source kept its show reference and its hide callback
never ran. Projectors of a scene and the multiview show scenes the same
way, and a scene that left the Program right after a hide kept it
queued as well.

Apply the pending audio actions of a scene that is not active from its
video tick. It mixes no audio, so nothing is lost by applying them at
once. Active scenes are unchanged.

With the fix, under xvfb (both ENABLE_RUST_LIBOBS lanes, with the built
OpenGL module and the system one masked), the hidden source gets its
hide callback and drops its show reference within a few ticks in all
six cases; the controls are unchanged.

Reported upstream in obsproject/obs-studio#4120 by Bobber-bob;
confirmed by Fenrirthviti and diagnosed by PatTheMav.

Fixes obs-rust#357.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=f2d19479568b293c020406c523999d7939d2c808 secs=154 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791800361,"gate":"rust/all/fmt","host":"linux-x86_64","key":"4f0eb4ebedc92189332681bdd5abf5ecc4a3b96b1019ad791c6ed960aba82383","lane":"lint","parents":["b327cfad2aa8bb3b40803a8bb741ef9480e8c53c"],"secs":56,"stamp":"6a9c8abae19e70beb712833bb0b36071","tree":"f2d19479568b293c020406c523999d7939d2c808","v":1,"via":"run"}
Ci-Attestation: {"at":1791800361,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"4f0eb4ebedc92189332681bdd5abf5ecc4a3b96b1019ad791c6ed960aba82383","lane":"lint","parents":["b327cfad2aa8bb3b40803a8bb741ef9480e8c53c"],"secs":56,"stamp":"d5aa3ba353faacd6e13aeebdf2a561de","tree":"f2d19479568b293c020406c523999d7939d2c808","v":1,"via":"run"}
Ci-Attestation: {"at":1791800361,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"ecd339ab6f8db57191f221bad4621df4da86360e71b8578cfa23ade39f5b45e0","lane":"rust-test","parents":["b327cfad2aa8bb3b40803a8bb741ef9480e8c53c"],"secs":47,"stamp":"e86924b87149beff1352bac0a00311ca","tree":"f2d19479568b293c020406c523999d7939d2c808","v":1,"via":"run"}
Ci-Attestation: {"at":1791800361,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a56a955930ac926a67c502d73cae842c5b857759f464a52cfb0e85349af1cf35","lane":"tier2-linux","parents":["b327cfad2aa8bb3b40803a8bb741ef9480e8c53c"],"secs":51,"stamp":"c31ddeb692c9d4768286110c85dfea86","tree":"f2d19479568b293c020406c523999d7939d2c808","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally under xvfb-run, 3 runs per commit:

  • RED b327cfa: 3/3 runs fail hide_preview_only_audio, hide_preview_only_group, hide_then_move_to_preview (3 pass)
  • GREEN 525b770: 3/3 runs pass 6/6

Without a display the test skips and reports Passed, so plain Tier 2 / CI doesn't exercise it. Rebased on master, local gate passed; pushed as 452cb14.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: hiding a source that is only in the Studio Mode preview never hides it ("Shutdown source when not visible" never fires) (upstream #4120)

2 participants