Repository navigation
libobs: Keep swapped slots inactive on failed add - #2497
Merged
Merged
Conversation
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
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
enabled auto-merge
October 26, 2026 16:02
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2486
What and why
obs_transition_swap_begin()hands each slot of the old transition to the new one incopy_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 nextobs_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 theirdeactivate/hidecallbacks 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 ofobs_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.mdnow names both fixes in its note on the slot flag. The stand-in models ofcopy_source_state()intest/cmocka/test_transition_start_steps.candrust/obs-source/tests/source/transition_start.rscopy 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,graphicssuite intest-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
test: Check transition swap active counts).test_transition_swap_activefails 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.test_transition_swap_active4/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/masterand--lane crosspass.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC