Skip to content

libobs: Store the transition matrices under the transition mutex - #3640

Merged
vpacher merged 2 commits into
masterfrom
fix/3570-transition-matrices
Nov 4, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/3570-transition-matrices

Conversation

@vpacher

@vpacher vpacher commented Nov 4, 2026

Copy link
Copy Markdown
Member

Refs #3570

What and why

The transition_matrices part of #3570. The other fields of that issue are not in this PR.

The graphics thread stores the matrices in the tick, and a caller of obs_transition_start() stores them too, with no lock. matrix4_copy() writes four vectors, so a render can use a torn matrix for a frame. This was the largest group in nightly 41851659014: 48 of 242 reports in OBS and test code.

  • recalculate_matrix stores the matrix under transition_mutex, in obs_source::transition_size and in libobs/obs-source-transition-size.c.h, so Tier 3 still compares them. No call into a child source happens while the lock is held, so this adds no lock order.
  • render_child() uses the copy that the render already takes under that lock, in place of the field. The two other reads already use that copy.

RED → GREEN

  • RED: the first commit makes the Tier 1 fake panic on a matrix stored without the lock: 9 tests fail.
  • GREEN: transition_* Tier 1 and Tier 3 pass (259). Local gate: all Linux lanes passed.
  • Windows (local VM, MSVC, because a core PR runs no Windows lane): hybrid and C reference build, identical exports (1795 symbols), the 11 transition Tier 2 tests pass against both, and the Rust transition_* tests pass.
  • ThreadSanitizer, local build, 5 tests that showed the race:
Test Reports before Reports after With matrix4_copy after
test_source_transition_size 18 13 0
test_transition_swap 8 4 0
test_transition_audio_rescale 12 4 0
test_transition_recursive_destination 47 32 0
test_stinger_media_duration 65 44 0

One run on each side. The reports that remain are other fields of #3570 and other issues.

  • Real app (UI, protocol output or logging changes): not applicable. I did not run it in the app.
  • Test cost: no new tests. Existing tests changed their expected order.

Performance

The tick takes the lock 2 more times per transition per frame, with no contention in the normal case. I did not measure it.

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 (not applicable: no warning or flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no difference, the C changes with the Rust)

🤖 Generated with Claude Code

vpacher and others added 2 commits November 4, 2026 22:26
The Tier 1 fake now panics on a matrix stored without transition_mutex. The
graphics thread and a caller of obs_transition_start() both store them, so
matrix4_copy() races with itself. The tests fail until the store takes the
lock.

Refs #3570

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The graphics thread (tick) and a caller of obs_transition_start() both store
the matrices, and matrix4_copy() writes four vectors, so a render could use a
torn matrix. Store them under transition_mutex, with no call into a child
source while it is held. render_child() uses the copy taken under the lock in
place of the field. The C file changes with the Rust core, so Tier 3 still
compares them.

Refs #3570

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=b441027c4cd2d1990a07fa181381332bffb3393e secs=287 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793828334,"gate":"rust/all/fmt","host":"linux-x86_64","key":"26b9ce2d81dfc576f42a06f96780597da545447e3093d01e3696d0c7e1d8fc3c","lane":"lint","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":83,"stamp":"fc7c0a8a59b7c6dd2d4f9609abb4ec1e","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"26b9ce2d81dfc576f42a06f96780597da545447e3093d01e3696d0c7e1d8fc3c","lane":"lint","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":83,"stamp":"2eae3e8bc865f4bd24708139ebf22b35","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"4f5b450c6a9aa3268beee4f7a68f4c1f1d7849a192565c0e6a5a9456b07515b2","lane":"rust-test","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":101,"stamp":"80d001200d0c80a67c28acca1218b6a6","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"009834a90b341a796596287cff1eac2b31946eead7d8ccb9d3e6d4325b6a57bf","lane":"cross","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":75,"stamp":"523ffc66d983ddf3ffd5c6f1e7990885","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"009834a90b341a796596287cff1eac2b31946eead7d8ccb9d3e6d4325b6a57bf","lane":"cross","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":75,"stamp":"f5eff42039f9d0048daee52d46b655c5","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"009834a90b341a796596287cff1eac2b31946eead7d8ccb9d3e6d4325b6a57bf","lane":"cross","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":75,"stamp":"50c946cffe0027628327a2a1b83a81f7","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"009834a90b341a796596287cff1eac2b31946eead7d8ccb9d3e6d4325b6a57bf","lane":"cross","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":75,"stamp":"fc122a10c0ba722bc18df81af9dab7e4","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
Ci-Attestation: {"at":1793828334,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"43acc412cd197cc099cab97688568d63e5473ad1a10e2631863608686b0653e9","lane":"tier2-linux","parents":["b8fb63d52f35ea70971db847f48e1dd1d764bb60"],"secs":286,"stamp":"8d1d4bff18e40ae60c6dc04899e6f9d3","tree":"b441027c4cd2d1990a07fa181381332bffb3393e","v":1,"via":"run"}
@vpacher
vpacher requested a review from zackees as a code owner November 4, 2026 21:48
@vpacher
vpacher enabled auto-merge November 4, 2026 21:49
@vpacher
vpacher added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit 167da60 Nov 4, 2026
38 checks passed
@vpacher
vpacher deleted the fix/3570-transition-matrices branch November 4, 2026 22:12
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.

1 participant