Skip to content

libobs: Compute a scene item's transform under the parent's video lock (#2115) - #2126

Merged
zackees merged 1 commit into
masterfrom
fix/scene-transform-lock
Oct 24, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/scene-transform-lock

Conversation

@zackees

@zackees zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member

Fixes #2115 (decided on the issue: the split version of option 1).

update_item_transform is split in two:

  • compute_item_transform: the arithmetic, unchanged.
  • The wrapper: reads the source size first, computes under video_lock(item->parent), then sends item_transform after unlocking.

Why this order:

  • The scene's video_mutex is recursive. The render path (update_transforms_and_prune_sources, resize_group, resize_scene_base) already holds it, so nothing changes there; that includes its signal, which is still sent under the caller's lock as before.
  • The UI setters (do_update_transform, scene_load_item, group apply and remove, obs_sceneitem_force_update_transform) now compute under the lock.
  • Nothing under the new lock calls plugins or takes another lock. get_width and get_height run before locking because they can reach plugin code. The scene and canvas dimension reads are plain.
  • No signal is sent while the new lock is held, so frontend handlers that enter graphics can't invert the render thread's graphics → video_mutex order.
  • Getters still see the new transform immediately.

RED: TSan run 40074741825 on master has 46 reports of update_item_transform (obs-scene.c.h:420/421) against source_size_changed (:504). Only TSan shows the race, so there's no Tier 2 RED. GREEN is the TSan run dispatched on this branch, and I'll post its counts. ./lint passes; Tier 2 in PR CI checks transforms are unchanged.

#2115)

Setters such as obs_sceneitem_set_pos update the transform on the caller
thread while the graphics thread reads it under the scene's video lock.
Split update_item_transform: read the source size first, compute under
video_lock(item->parent) (recursive, already held on the render path),
then send item_transform after unlocking so its handlers can't invert
the graphics -> video lock order.

Fixes #2115
@zackees
zackees enabled auto-merge October 24, 2026 10:16
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into master with commit 1cddf78 Oct 24, 2026
37 checks passed
@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

GREEN: TSan run 40085244173 on this branch has 0 update_item_transform ↔ source_size_changed reports, against 46 in master run 40074741825.

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.

libobs: scene item setters update the transform on the caller thread without the scene lock (data race with render)

1 participant