Skip to content

frontend: Queue scene changes that scripts make from a timer - #1417

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/lua-timer-scene-switch
Oct 18, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/lua-timer-scene-switch

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1416

What and why

A Lua or Python script that switches scenes from a timer no longer hangs OBS when it also has a frontend event callback (upstream obsproject/obs-studio#3385, reported by woganmay in 2020, confirmed by RytoEX; PatTheMav traced the deadlock).

  • obs_frontend_set_current_scene() (frontend/OBSStudioAPI.cpp.hpp) ran the scene change on the UI thread with WaitConnection() and waited for it.
  • Script timers run in a tick callback on libobs's graphics thread, holding the scripting callback lock (the GIL for Python). The scene change sends frontend events to the scripts' event callbacks on the UI thread, and those take the same lock. The graphics thread waited for the UI thread, and the UI thread waited for the lock: OBS stopped responding, preview and obs-websocket included.
  • Called on libobs's graphics, audio or destroy thread, the scene change is now queued and the call returns, as the profile calls already do through RunFrontendApiCall() (frontend: Wait for profile changes made through the frontend API #805). The graphics thread must not wait for the UI thread anyway, because the UI thread waits for it. Called from any other thread (obs-websocket's pool, a plugin's own thread) it still waits until the scene has changed, so SetCurrentProgramScene followed by GetCurrentProgramScene behaves as before. The Studio Mode path (TransitionToScene) does the same.
  • What changes for scripts: a timer that calls obs_frontend_set_current_scene() gets control back before the scene has changed. The change happens right after, on the UI thread. Before, the call never returned.
  • InLibobsThread() moves above its new first user, and its comment now says why these threads must not wait.

RED → GREEN

  • RED commit: 5b0540d test: Add failing Tier 4 phase for a Lua timer that switches scenes. run_tier4.py --only scripts (also part of the full run, before the GPU phase) starts OBS with scenes A and B and a Lua script that adds an event callback and, from a 2 s timer, calls obs_frontend_set_current_scene(B). On v0.1.0-beta.20261018 and on master 065fa7d (C lane, built with Lua) 2 of 4 checks fail. obs_frontend_set_current_scene from a Lua timer returns: the script logs "switching to B" and never gets past the call. UI thread still answers after the switch: SetCurrentProgramScene times out, OBS hangs. B does reach program before the UI thread blocks. The phase fails, not skips, when the script never runs (a build without Lua): CI's Ubuntu build installs swig and LuaJIT.
  • GREEN: af0db1a. The scripts phase passes 4 of 4, 3 of 3 runs. The full Tier 4 suite on this build, rebased on master with the shutdown phase from frontend: Quit on SIGTERM while outputs run or a dialog waits #1403: 203/203 checks, 147/147 documented request types. The change is in the frontend only. libobs is the same C build in both lanes, so I built the C lane, with Lua.
  • Real app: the Tier 4 phase above is the real app (private Xvfb, private D-Bus, fresh HOME), with the script loaded by the Scripts tool from the scene collection.

Checklist

  • Base is master
  • 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
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Scripting)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

AI note: Claude Code (Claude Opus 5.5) wrote the code, the test, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

@zackees
zackees added this pull request to the merge queue Oct 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 18, 2026
A Lua script that calls obs_frontend_set_current_scene() from a timer
and also has a frontend event callback hangs OBS
(obsproject/obs-studio#3385, reported by woganmay). Script timers run
on libobs's graphics thread holding the scripting callback lock. The
call waits for the UI thread, and the UI thread, sending the scene
change to the script's event callback, waits for that lock.

The new phase (run_tier4.py --only scripts, also part of the full run)
starts OBS with scenes A and B and such a script, which switches to B
from a 2 s timer. It checks that the call returns, that B is on
program and that the UI thread still answers SetCurrentProgramScene.
On v0.1.0-beta.20261018 and master 065fa7d 2 of 4 checks fail: the
call never returns and SetCurrentProgramScene times out.

Refs obs-rust#1416
obs_frontend_set_current_scene() ran the scene change on the UI thread
and waited for it. Script timers run on libobs's graphics thread with
the scripting callback lock held (the GIL for Python), and the scene
change sends frontend events to the scripts' event callbacks on the UI
thread, which take that lock. A script that switched scenes from a
timer and also had an event callback deadlocked OBS
(obsproject/obs-studio#3385).

Called on libobs's graphics, audio or destroy thread, the scene change
is now queued and the call returns, as the profile calls already do
through RunFrontendApiCall() (obs-rust#805). Called from any other thread
(obs-websocket, plugins' own threads) it still waits until the scene
has changed. The Studio Mode path (TransitionToScene) does the same.

The Tier 4 scripts phase passes 4 of 4.

Fixes obs-rust#1416
@rdoupe
rdoupe force-pushed the fix/lua-timer-scene-switch branch from 6677717 to af0db1a Compare October 18, 2026 16:12
@zackees
zackees enabled auto-merge October 18, 2026 16:13
@zackees
zackees added this pull request to the merge queue Oct 18, 2026
Merged via the queue into obs-rust:master with commit ee7ef9a Oct 18, 2026
22 checks passed
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.

bug: frontend: a script that switches scenes from a timer hangs OBS when it also has a frontend event callback (upstream #3385)

2 participants