Skip to content

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

Closed

Description

@zackees

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:

  1. 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.
  2. 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.

Activity

  1. added
    bug
    on Oct 24, 2026
  2. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    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.

  3. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    Lock-order audit for option 1:

    • 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?

  4. added
    decision-needed
    on Oct 24, 2026
  5. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    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.
  6. removed
    decision-needed
    on Oct 24, 2026
  7. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    Claiming: this issue.

  8. added
    claimed
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclaimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions