Skip to content

libobs: Keep slot A inactive after a failed add - #2485

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/transition-set-active
Oct 26, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/transition-set-active

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2484

What and why

obs_transition_set() marked slot A active even when its source could not be added as an active child of the transition. The add fails when the source contains the transition, for example a scene that holds the transition as an item. The next obs_transition_set() then removed an active reference the transition never added. The scene lost the reference of whatever else shows it (the output channel, or a projector), so the scene, every source in it and the transition were deactivated (or hidden) while still shown, and their deactivate/hide callbacks ran (a media source in that scene would stop). When the next set gave the transition another source, the scene's deactivation walked the transition, which already held that source before it was added, so the new source ended at -1 and was never shown. Upstream OBS Studio master has the same code; there is no upstream issue or fix.

The fix: when the add fails, clear slot A's flag again, if the slot still holds that source. The success path and the order of the remove and add calls are unchanged. The source is still stored in the slot, so obs_transition_get_source() is unchanged. obs_transition_load() already refuses such a source, and set_source() (used by obs_transition_start()) already marks nothing when its add fails.

The decision is in C: the Rust step obs_source_transition_start_child_active() (#2478) only combines "there is a child" and "the slot is active", and stays as it is. rust/README.md drops obs_transition_set() from its "kept, characterized, not endorsed" list.

Needs maintainer sign-off: the stand-in models in test/cmocka/test_transition_start_steps.c (the block "characterized, not endorsed: a set whose add fails still marks slot A active") and rust/obs-source/tests/source/transition_start.rs (the same case in the set test) copy the old obs_transition_set() and still assert the old flag. They do not call the real function, so they still pass, but they no longer describe it. Existing C test assertions are not changed here (AGENTS.md); retiring both lines is a follow-up for a maintainer to approve.

New test test_transition_set_active (real libobs, core video, Linux under xvfb-run, graphics suite in test-graph.json): a scene holds a leaf source and the transition.

  • cycle_keeps_output_channel_reference: the scene is output channel 0's source; set the transition to the scene, then to nothing; the scene, leaf and transition keep 1/1 activate/show counts and the leaf gets no deactivate or hide callback.
  • cycle_keeps_shown_reference: the same with the scene shown only (obs_source_inc_showing(), as a projector does).
  • acyclic_source_is_held_and_released (control): a source outside the cycle is activated by the transition and released by the next set.
  • cycle_then_acyclic_source: a cyclic source replaced by an acyclic one; the scene keeps its counts and the new source is held, then released.

Not in this PR, found while testing (same fixture, scratch probe):

  • obs_transition_swap_begin() (copy_source_state()) has the same imbalance: it copies the source's slot flag to the destination transition even when its add there fails. After a swap into a transition that the scene contains, the next set took the scene's references away.
  • While slot A holds a source that contains the transition, walking that source's active tree goes through the transition back to it and locks the transition's non-recursive mutex twice: obs_source_inc_showing(scene) did not return within 5 seconds. Any walk would do the same, for example the audio thread's walk of an output channel.

RED → GREEN

  • RED commit: 13b6b1fc2 (test: Check obs_transition_set active counts). test_transition_set_active fails 3 of 4 cases on the C build, hybrid libobs and libobs-c-reference (the control passes). For example: after clearing the cycle: 'cycle scene' activate_refs=0 show_refs=0, expected 1/1, 'leaf' activate=1 deactivate=1 show=1 hide=1, expected 1/0/1/0, after replacing the cycle: 'other' activate_refs=-1 show_refs=-1, expected 1/1.
  • GREEN: e5c10aa6e. test_transition_set_active 4/4 on all three lanes. The affected ctest set (transition|scene|studio_mode|fade|stinger|group|source_active|swap) passes with no skips: 49/49 on the C build, 58/58 on hybrid libobs, 58/58 against libobs-c-reference (rebuilt first). Exported symbols are the same on all three. Local gate: --lane lint, --test-diff origin/master and --lane cross pass.
  • Real app (UI, protocol output or logging changes): N/A. The UI cannot put a transition into a scene; plugins and scripts can.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

obs_transition_set() marks slot A active even when the source cannot be
added as an active child (it contains the transition). The next call
then removes a reference the transition never added, so the program
scene, the sources in it and the transition are deactivated while the
output channel still shows the scene, and a source set after the cycle
ends up with negative counts.

Refs obs-rust#2484
obs_transition_set() marked slot A active even when its source could
not be added as an active child of the transition, which happens when
the source contains the transition. The next set then removed an
active reference the transition never added, so a scene shown in
Program or a projector, the sources in it and the transition itself
were deactivated while still shown, and a source set after the cycle
ended up with negative counts.

Clear the flag again when the add fails and slot A still holds the
source. The success path is unchanged, and the source is still stored
in the slot as before.

Fixes obs-rust#2484
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: correct. When obs_source_add_active_child() fails (the source contains the transition), slot A's flag is cleared under the transition lock, guarded by a check that the slot still holds that source. So the next set no longer drops a reference another parent holds. The change is in obs-source-transition.c.h, which the C, hybrid and libobs-c-reference builds all compile, so no Rust diverges, and README's 'characterized, not endorsed' note is updated to match. A new graphics-suite test is added, no existing test changes, and the ledger line is in. Queuing.

@zackees
zackees enabled auto-merge October 26, 2026 14:32
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit d4df6b3 Oct 26, 2026
36 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 26, 2026
* test: Check transition swap active counts

Swap a transition that holds a scene into a transition inside that
scene, then set it to nothing or to another source, and check the
activate/show counts of the scene, its sources and the transition.
The swap marks the slot active although the add of the scene failed
(a cycle), so the set takes the scene's references away.

Refs obs-rust#2486

* libobs: Keep swapped slots inactive on failed add

copy_source_state() copied the old transition's slot flag to the new
one even when the add of that slot's source on the new transition
failed (the source contains the new transition). The next
obs_transition_set() then removed an active reference the new
transition never had, taking the scene's references away from its
other parent. Clear the flag when the add fails, as obs-rust#2485 does for
obs_transition_set().

Fixes obs-rust#2486
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: obs_transition_set takes away another parent's active reference after a cycle

2 participants