Skip to content

libobs: Keep swapped slots inactive on failed add - #2497

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

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

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2486

What and why

obs_transition_swap_begin() hands each slot of the old transition to the new one in copy_source_state(): the source, the slot's active flag, and for an active slot an active child reference from the new transition. That add fails when the source contains the new transition (a cycle: a scene that holds the new transition as an item), so the new transition holds no reference on the source, but the slot was still marked active. The next obs_transition_set() then removed an active reference the new transition never added and took away the reference of whatever else shows the scene (the output channel, or a projector): the scene, every source in it and the transition were deactivated (or hidden) while still shown, and their deactivate/hide callbacks ran. When that set gave the transition another source, the new source ended at -1 and was never shown. This is the loss of #2484, reached through the swap (the frontend swaps when the transition is changed) instead of obs_transition_set(). Upstream OBS Studio master has the same code; there is no upstream issue or fix.

The fix: when the add fails, clear the destination slot's flag again, as #2485 does for obs_transition_set(). The success path, the order of the calls and the stored source are unchanged.

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; the flag is written in C. rust/README.md now names both fixes in its note on the slot flag. The stand-in models of copy_source_state() in test/cmocka/test_transition_start_steps.c and rust/obs-source/tests/source/transition_start.rs copy the old function; neither has a case with a failed add in the swap, so nothing there asserts the old flag, and no existing test is changed.

New test test_transition_swap_active (real libobs, core video, Linux under xvfb-run, graphics suite in test-graph.json): a scene holds a leaf source and a transition; a second transition outside the scene is set to a source and swapped into the first one.

  • swap_cycle_keeps_output_channel_reference: the scene is output channel 0's source; swap in the scene, then set the transition to nothing; the scene, leaf and transition keep 1/1 activate/show counts and the leaf gets no deactivate or hide callback.
  • swap_cycle_keeps_shown_reference: the same with the scene shown only (obs_source_inc_showing(), as a projector does).
  • swap_acyclic_source_is_held_and_released (control): a source outside the cycle is handed over with its active reference and released by the next set.
  • swap_cycle_then_acyclic_source: a swapped-in cyclic source replaced by an acyclic one; the scene keeps its counts and the new source is held, then released.

Not in this PR: after the swap the destination slot still stores the source that contains the transition, so a walk of the scene's active tree while it is stored (showing the scene again, or the audio thread's walk of an output channel) locks the transition's mutex twice and hangs, the hang of #2487 reached through the swap. A probe on top of #2487's fix (swap the cycle in, then obs_source_inc_showing(scene)) did not return within 5 seconds. The test keeps that window to a few calls, and passed 20 of 20 repeated runs.

RED → GREEN

  • RED commit: f38b81e (test: Check transition swap active counts). test_transition_swap_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 0/1, 'leaf' activate=0 deactivate=0 show=1 hide=1, expected 0/0/1/0, after replacing the cycle: 'other' activate_refs=-1 show_refs=-1, expected 1/1.
  • GREEN: e1ced8b. test_transition_swap_active 4/4 on all three lanes (20/20 repeated runs on the C build; all cases skip without a display). The affected ctest set (transition|scene|studio_mode|fade|stinger|group|source_active|swap) passes with no skips: 50/50 on the C build, 59/59 on hybrid libobs, 59/59 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)

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
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
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: the same fix as #2485, applied to copy_source_state() for swaps. When the active-child add fails (a cycle), the slot is marked inactive, so the next set doesn't drop another parent's reference. A new graphics test is added, no existing test changes, and the ledger line is in. Queuing.

@zackees
zackees enabled auto-merge October 26, 2026 16:02
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit f80d014 Oct 26, 2026
36 checks passed
@rdoupe rdoupe mentioned this pull request Oct 26, 2026
3 of 7 tasks
vpacher pushed a commit to vpacher/obs-studio that referenced this pull request Oct 26, 2026
* test: Check transition swap does not store cycle

Swap a transition that holds a scene (a scene holding that scene, or
the destination transition itself) into a transition inside that
scene, and check that the destination slot is left empty and that
showing the scene again returns, under a 5-second watchdog. The swap
stores the source although the destination could not add it, so the
walk enters the transition again and hangs on its mutex.

Refs obs-rust#2499

* libobs: Leave swapped slot empty on cycle

copy_source_state() stored the old transition's slot source in the
new transition even when the add of that source failed because it
contains the new transition (or is that transition). obs-rust#2497 cleared
the slot flag, but the slot still held the cycle, so showing the scene
walked into the transition again and locked its mutex twice. Release
the source and leave the slot empty, with a warning, as
obs_transition_set() refuses such a source.

Fixes obs-rust#2499
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_swap_begin copies an active flag after a failed add

2 participants