You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
libobs: scene item setters update the transform on the caller thread without the scene lock (data race with render) #2115
do_update_transform (libobs/obs-scene.c.h:2465, upstream code) calls update_item_transform(item, false) immediately when the item's parent is a plain scene. Callers include obs_sceneitem_set_pos, set_rot, set_scale and the others, normally on the UI thread, and none of them takes the scene lock. Meanwhile the graphics thread reads the same fields (last_width/last_height, the draw and box transforms) in update_transforms_and_prune_sources → source_size_changed (:504) and in render, while holding the scene's mutexes.
TSan run 40074741825 (master) has 46 reports of update_item_transform (:420/:421) against source_size_changed (:504), e.g. test_group_empty_bounds via obs_sceneitem_set_pos. Effect: a frame rendered with a half-updated transform, which is visual only.
Options:
Take full_lock(item->parent) around the immediate update. First check every setter for re-entry from render callbacks: the scene mutexes are recursive, but lock order against the graphics context needs checking.
Always set update_transform and let the render thread apply it. That changes when getters see the new transform, which callers such as the frontend rely on.
Unclaimed: this needs a decision between 1 and 2, or someone checking upstream for a fix.
Checked upstream: obsproject/obs-studio master libobs/obs-scene.c has the same do_update_transform (immediate update_item_transform(item, false) for a plain-scene parent, no lock) and obs_sceneitem_set_pos takes no lock either. So no upstream fix to pull; the race is upstream behavior and this needs the decision between options 1 and 2.
video_mutex is recursive (scene_create), and the render thread takes it in update_transforms_and_prune_sources (:809/:855) while holding the graphics context.
update_item_transform ends with signal_parent(item->parent, "item_transform", ...). Frontend handlers of that signal can call obs_enter_graphics (the preview, for example).
So wrapping the immediate update in video_lock(item->parent) puts UI(video_mutex → graphics) against render(graphics → video_mutex): a deadlock. Plain option 1 is unsafe.
Safe version of option 1: split update_item_transform into a compute step, run under video_lock(item->parent), and the item_transform signal, sent after unlocking. That covers the 11 do_update_transform sites plus the direct callers scene_load_item, apply_group_transform/remove_group_transform, resize_group and obs_sceneitem_force_update_transform. Every caller keeps seeing the new transform immediately, and no signal is sent while the lock is held. I recommend this over option 2. Decision needed: OK to proceed with the split?
Decided: proceed with the split version of option 1: compute the transform under video_lock(item->parent), send item_transform after unlocking, at all the sites the audit lists.
Reasons:
Option 2 changes when public getters see a new transform. AGENTS.md requires the libobs C API to stay compatible, and the frontend relies on the immediate update.
Plain option 1 deadlocks (UI: video_mutex → graphics vs render: graphics → video_mutex), per the audit above.
The split keeps the API behavior, removes the race and is reversible. Tier 3 differential behavior is unchanged: the C oracle computes the same transform, just without the lock.
Cover it with a TSan-clean run of the reported tests (e.g. test_group_empty_bounds) plus a test that a getter sees the new transform right after the setter.
Activity
zackees commentedon Oct 24, 2026
Checked upstream: obsproject/obs-studio master
libobs/obs-scene.chas the samedo_update_transform(immediateupdate_item_transform(item, false)for a plain-scene parent, no lock) andobs_sceneitem_set_postakes no lock either. So no upstream fix to pull; the race is upstream behavior and this needs the decision between options 1 and 2.zackees commentedon Oct 24, 2026
Lock-order audit for option 1:
video_mutexis recursive (scene_create), and the render thread takes it inupdate_transforms_and_prune_sources(:809/:855) while holding the graphics context.update_item_transformends withsignal_parent(item->parent, "item_transform", ...). Frontend handlers of that signal can callobs_enter_graphics(the preview, for example).video_lock(item->parent)puts UI(video_mutex → graphics) against render(graphics → video_mutex): a deadlock. Plain option 1 is unsafe.Safe version of option 1: split
update_item_transforminto a compute step, run undervideo_lock(item->parent), and theitem_transformsignal, sent after unlocking. That covers the 11do_update_transformsites plus the direct callersscene_load_item,apply_group_transform/remove_group_transform,resize_groupandobs_sceneitem_force_update_transform. Every caller keeps seeing the new transform immediately, and no signal is sent while the lock is held. I recommend this over option 2. Decision needed: OK to proceed with the split?zackees commentedon Oct 24, 2026
Decided: proceed with the split version of option 1: compute the transform under
video_lock(item->parent), senditem_transformafter unlocking, at all the sites the audit lists.Reasons:
zackees commentedon Oct 24, 2026
Claiming: this issue.
libobs: Compute a scene item's transform under the parent's video lock (