Skip to content

libobs: Refuse a cycle in obs_transition_set - #2498

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

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

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2487

What and why

obs_transition_set() stored any source in slot A, even one that contains the transition (a scene that holds the transition as an item, a scene holding that scene, or the transition itself). obs_transition_load() refuses such a source with "infinite recursion", and obs_transition_start() refuses such a destination before it changes anything, but set did not. While the slot holds it, the source's tree goes through the transition back to the source, so any walk of its active tree (showing or activating the scene, or the audio thread's walk of an output channel) enters the transition a second time and locks its non-recursive mutex twice: OBS hangs. Upstream OBS Studio master has the same code; there is no upstream issue or fix.

The fix: obs_transition_set() first runs the recursion walk of obs_transition_start() over the new source (check_transition_recursion(), with obs_source_transition_start_walks() from #2478 deciding whether it runs, and the transition itself counting as recursive). On a cycle it logs a warning and returns before changing anything: no stop signal, both slots and their flags stay as they were, so the transition keeps its source. Every other source is set as before. obs_transition_set() already walked the new source's tree once (inside obs_source_add_active_child()), so the extra walk takes no lock that set did not already take.

The walk decision stays the Rust walks() (rust/obs-source transition_start), unchanged; it now has a second caller, named in its doc comments, the header and rust/README.md. No Tier 1 test changes: the function's rule is the same.

How this fits with #2485 (merged): #2485 keeps slot A inactive when the add of its source fails. After this PR, set no longer reaches that add with a cycle, so #2484's case needs the add to fail although the walk just before it found no cycle. Both walks test the same edges, and obs_scene_add() refuses to add the transition to a scene it holds, so that should not happen; #2485 stays as the backstop, and each fix is correct without the other. With obs_transition_start(): its pre-check is unchanged, and its own calls of obs_transition_set() (finishing a running transition, and the manual reset) pass a source the transition already holds, which passed the same check when it came in.

Needs maintainer sign-off: the stand-in model of obs_transition_set() in test/cmocka/test_transition_start_steps.c (the block "characterized, not endorsed: a set whose add fails still marks slot A active") and the one in rust/obs-source/tests/source/transition_start.rs copy the old function and do not refuse a cycle. 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 that line is a follow-up for a maintainer to approve (it is the same line #2485 left).

New test test_transition_set_cycle (real libobs, core video, Linux under xvfb-run, graphics suite in test-graph.json): a scene holds a leaf source and the transition, and an outer scene holds that scene. Each case sets the transition to an unrelated source, makes the scene output channel 0's source, sets the transition to the cycle, and checks that slot A still holds the unrelated source, that showing the scene again returns, and that the activate/show counts and the leaf's callbacks are right. The walk runs under a watchdog thread: if it has not returned after 5 seconds, the test prints HANG: ... and exits with a failure, so a hang fails instead of stalling CI.

  • set_acyclic_source_is_stored (control): a source outside the cycle is stored, held, and released by the next set.
  • set_containing_scene_is_refused: the scene that holds the transition.
  • set_outer_scene_is_refused: the outer scene (the cycle is two levels deep).
  • set_itself_is_refused: the transition itself.

Not in this PR: obs_transition_swap_begin() can still store such a source. A transition outside the scene that holds the scene, swapped into a transition the scene contains, leaves the scene in the destination's slot A; a probe on top of this fix (swap, then obs_source_inc_showing(scene)) hung the same way. #2486 fixes the reference counts of that swap, not the stored cycle.

RED → GREEN

  • RED commit: 0ce5771 (test: Check obs_transition_set refuses a cycle). On the C build, hybrid libobs and libobs-c-reference, the control passes, then set_containing_scene_is_refused reports slot A holds 'cycle scene', expected 'other' and HANG: showing the scene after setting the scene that holds the transition did not return within 5000 ms, and the watchdog ends the test binary (about 6 s) with a failure.
  • GREEN: fd508aa. test_transition_set_cycle 4/4 on all three lanes, each refused set logged once (3 warnings); 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. The new warning is obs_transition_set: cannot set transition '<name>' to source '<name>' due to infinite recursion.

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)

@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: correct. obs_transition_set() now refuses a source that contains the transition (or is the transition), with the same recursion walk and warning that obs_transition_load() and obs_transition_start() already use, before changing anything. That's what prevents the double lock. transition_start.rs's walk rule is widened to match, with its parity test. A new test is added and no existing assertion changes. Queuing.

@zackees
zackees enabled auto-merge October 26, 2026 16:02
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 26, 2026
Set a transition to a scene that holds it, to a scene holding that
scene and to itself, and check that the set is refused and that
showing the scene again returns. obs_transition_set() stores the
cycle, and the walk of the scene's tree locks the transition's mutex
twice: a watchdog thread fails the test after 5 seconds instead of
letting it hang.

Refs obs-rust#2487
obs_transition_set() stored a source that contains the transition
(or the transition itself) in slot A. A walk of that source's active
tree then entered the transition again and locked its mutex twice:
showing the scene hung. Refuse such a source before changing anything,
with the recursion walk obs_transition_start() uses, and log it, as
obs_transition_load() does.

Fixes obs-rust#2487
@rdoupe
rdoupe force-pushed the fix/transition-set-cycle branch from fd508aa to ea3394f Compare October 26, 2026 16:41
@zackees
zackees enabled auto-merge October 26, 2026 16:52
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit b13780b Oct 26, 2026
36 checks passed
@rdoupe rdoupe mentioned this pull request Oct 26, 2026
3 of 7 tasks
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 accepts a source that contains the transition (hang)

2 participants