Skip to content

libobs: Move the active-child link when an item changes group - #242

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/241-group-active-refs
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/241-group-active-refs

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Description

Moving a source into a hidden group (or out of one) no longer leaves its active/show counts wrong. Before this change, a source moved into a hidden group kept playing audio and stayed in the mixer, even after the group and the source were deleted; a source moved out of a hidden group was visible but never activated.

A visible scene item's source is an active child of the scene that holds it. obs_sceneitem_group_add_item(), obs_sceneitem_group_remove_item(), obs_scene_reorder_items2() (the source tree's drag and drop) and obs_scene_insert_group() move items between a scene and a group's scene without moving that relationship, so activation and deactivation walk different trees.

  1. test: Group moves must keep activate/show counts balanced: test_group_active_refs runs core video and audio, builds scenes and groups, and checks the raw activate_refs/show_refs after each step, finishing every case by deleting everything while the scene is on the output (the counts must return to exactly 0). 6 of 10 cases fail on this commit: drag and drop into and out of a hidden group, group_add_item and group_remove_item with a hidden group, a nested scene dragged into a hidden group, and swapping sources between a hidden and a visible group. The 4 controls pass: a visible group, a hidden item, obs_scene_insert_group() with a hidden item, and kpaulisse's nested-scene studio-mode setup.
  2. libobs: Move the active-child link when an item changes group: a move_active_child() helper, called from the four functions, adds a visible item's source as an active child of its new scene and then removes it from the old one. Adding first means a source that stays on screen never drops to zero in between; hidden items hold no activation and are skipped. All 10 cases pass.

Why this approach: the activation state is not stored per link, it is recomputed by walking the tree, so the fix has to apply the difference at the moment the item changes scene. Lain-B closed the frontend workaround (#10417) because the bug is in the backend (obs-scene.c); fixing it there also covers every plugin and script that moves items through the API. It reuses obs_source_add_active_child()/obs_source_remove_active_child() exactly as obs_sceneitem_set_visible() does, and adds no API.

Motivation and Context

Fixes #241 (upstream obsproject/obs-studio#9961, reported by walker-WSH)

Why this one: a confirmed bug open upstream since 2023 (and in an earlier report since OBS 25), hit by ordinary drag and drop in the source tree. walker-WSH traced it to unmatched show_refs/activate_refs, kpaulisse reported the same symptoms, and Lain-B's review of #10417 pointed at obs-scene.c. Users hear audio from sources they have hidden or deleted.

How Has This Been Tested?

Automated: test_group_active_refs fails 6 of 10 at the RED commit and passes 10 of 10 at the GREEN commit; 10 of 10 repeated runs at GREEN pass. The full cmocka suite passes at GREEN (81 of 81). All runs used a private Xvfb with software GL. clang-format and gersemi are clean.

Reviewed every caller for double adds or removes. Hidden items, deleting an item after removing it from a group (what the frontend's Remove does) and obs_scene_insert_group() with mixed visibility have test cases. An item with a pending hide was checked by reading the code: the audio action later removes the link from the item's current parent, which is now the new one.

kpaulisse's variant (hide a group holding a nested scene while the parent scene is in program and in the studio mode preview) involves no move, and libobs already balances it, with and without audio flowing and with a duplicated program scene. It is kept as a control.

Not tested:

  • The frontend itself; the test calls the same libobs functions the source tree uses.
  • Windows and macOS (the test needs a display and runs on Linux only; the fix is platform-independent C).
  • A drag that moves an item out of one group while that group's audio thread is applying a pending hide for the same item. obs_scene_reorder_items2() already relinks that group's items without its lock; this change does not widen that.
  • The Rust and Docker lanes of the local gate.

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

Moving a scene item into or out of a group changes which scene holds it,
but the source stays an active child of the old scene. Activation and
deactivation then walk different trees: a source moved into a hidden group
stays active and showing after its scene goes off the output (audio keeps
playing, the mixer keeps listing it), and a source moved out of a hidden
group is never activated.

The test checks the raw activate/show counts through
obs_scene_reorder_items2() (what the source tree's drag and drop uses),
obs_sceneitem_group_add_item()/_remove_item() and obs_scene_insert_group(),
including a nested scene, a move between two groups and hidden items, and
ends every case by deleting everything while the scene is on the output,
where the counts must return to exactly zero. Visible-group, hidden-item,
insert_group and nested-preview cases are controls that already pass. It
fails on the six hidden-group move cases.

Reported upstream in obsproject/obs-studio#9961 by walker-WSH, with a
second report by kpaulisse.

Refs obs-rust#241.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 15:01
A visible scene item's source is an active child of the scene that holds
it. obs_sceneitem_group_add_item(), obs_sceneitem_group_remove_item(),
obs_scene_reorder_items2() and obs_scene_insert_group() move items into
or out of a group's scene without moving that link, so activation and
deactivation walk different trees and the source's activate/show counts
drift: a source moved into a hidden group stays active after its scene
leaves the output, and one moved out of a hidden group is never
activated.

Whenever a visible item changes parent, add its source as an active child
of the new parent, then remove it from the old one. Adding first means a
source that stays on screen (a move into a visible group) never drops to
zero in between. Hidden items hold no activation and are left alone.

Upstream: obsproject/obs-studio#9961 (reported by walker-WSH).

Fixes obs-rust#241.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=52d9f27104c1cd1471529804926d9a007e43b1ce secs=84 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791731633,"gate":"rust/all/fmt","host":"linux-x86_64","key":"a1eee73fbbdd9b2cd96aaf0757a5d1790f2fbb8fd52c00192d64ab12332db728","lane":"lint","parents":["01e8129cf812d32d5beea93d4b30329aef585cfd"],"secs":14,"stamp":"ddc6588cf6451995edaaa036113f7d6b","tree":"52d9f27104c1cd1471529804926d9a007e43b1ce","v":1,"via":"run"}
Ci-Attestation: {"at":1791731633,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"a1eee73fbbdd9b2cd96aaf0757a5d1790f2fbb8fd52c00192d64ab12332db728","lane":"lint","parents":["01e8129cf812d32d5beea93d4b30329aef585cfd"],"secs":14,"stamp":"f738b1ffa5a5eff74e09b0c51083caf4","tree":"52d9f27104c1cd1471529804926d9a007e43b1ce","v":1,"via":"run"}
Ci-Attestation: {"at":1791731633,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"0e88c2ccfb87d10b31714427d8354c5ff7e210a2bf4487fd14ba8edde7ed083d","lane":"rust-test","parents":["01e8129cf812d32d5beea93d4b30329aef585cfd"],"secs":29,"stamp":"93475932dfd7ac00d94a88aa20b7e64a","tree":"52d9f27104c1cd1471529804926d9a007e43b1ce","v":1,"via":"run"}
Ci-Attestation: {"at":1791731633,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"9506e2e235ff506757536d45ce23e24d9c3a5cea23346ddaf483f9f871f95970","lane":"tier2-linux","parents":["01e8129cf812d32d5beea93d4b30329aef585cfd"],"secs":40,"stamp":"ed610bbc9c47331d14b6457df332f66a","tree":"52d9f27104c1cd1471529804926d9a007e43b1ce","v":1,"via":"run"}
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The test skips without a display, so I ran it with xvfb-run ctest on each commit's Tier 2 build:

  • RED (01e8129cf): add_item_to_hidden_group, remove_item_from_hidden_group, reorder_between_groups, reorder_into_hidden_group, reorder_nested_scene_into_hidden_group and reorder_out_of_hidden_group failed.
  • GREEN (d9108cc02): the test passed. Plain Tier 2 passed 81 of 81 with ENABLE_RUST_LIBOBS OFF and 81 of 81 with it ON, and the local gate passed.

Merging once CI is green.

@zackees
zackees force-pushed the fix/241-group-active-refs branch from d9108cc to 9ce8e92 Compare October 11, 2026 15:13
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: moving a source into or out of a hidden group leaves it active (audio plays while hidden, or goes silent while visible) (upstream #9961)

2 participants