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
bug: frontend: a script that switches scenes from a timer hangs OBS when it also has a frontend event callback (upstream #3385) #1416
Upstream bug: obsproject/obs-studio#3385, reported by woganmay in September 2020. RytoEX confirmed the hang in OBS 28.0.3. PatTheMav traced it to a deadlock and suggested making script-triggered scene changes non-blocking. It is still open upstream, and still present in this fork.
Location
frontend/OBSStudioAPI.cpp.hpp, OBSStudioAPI::obs_frontend_set_current_scene(): it runs SetCurrentScene (or TransitionToScene in Studio Mode) on the UI thread with WaitConnection(), so the caller waits until the scene change is done.
shared/obs-scripting/obs-scripting-lua.c.h: script timers run in a tick callback on libobs's graphics thread, holding the scripting callback lock (lock_callback()).
shared/obs-scripting/obs-scripting-lua-frontend.c.h, frontend_event_callback(): the scene change sends frontend events to every script that added an event callback, on the UI thread, and that takes the same lock.
The graphics thread waits for the UI thread, and the UI thread waits for the lock the graphics thread holds. Python scripts take the same path.
Class
Hang. OBS stops responding (UI and obs-websocket), the preview freezes, and the user has to kill it. A recording or stream in progress is cut off.
How it is reached
A Lua or Python script that calls obs_frontend_set_current_scene() from a timer (timer_add), the usual way to switch scenes automatically, and that also has a frontend event callback (obs_frontend_add_event_callback). The upstream workaround was to remove the event callback around each switch, or to stay in Studio Mode.
Reproduced in the current release
v0.1.0-beta.20261018 AppImage and master 065fa7d (C lane, built with Lua scripting), headless (private Xvfb, private D-Bus, fresh HOME). A scene collection 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):
The script logs "switching to B", and the call never returns.
The program scene changes to B. Then the UI thread blocks in the script's event callback.
obs-websocket requests that need the UI thread (SetCurrentProgramScene) time out. OBS has to be killed.
Fix
obs_frontend_set_current_scene() called on libobs's graphics, audio or destroy thread queues the scene change and returns, as the profile calls already do through RunFrontendApiCall() (#805). From any other thread (obs-websocket, plugins' own threads) it still waits until the scene has changed. A script on a timer gets control back first and the scene changes right after, on the UI thread. A regression phase in the Tier 4 suite runs such a script in the real app. PR follows.
Claiming: RED is a Tier 4 phase (--only scripts) that runs the real app with a Lua script switching scenes from a timer; it fails on the release and on master. GREEN makes obs_frontend_set_current_scene() queue the change when called on a libobs thread. PR today.
@woganmay you reported this in obsproject/obs-studio#3385: OBS hung when a script switched scenes from a timer. That's fixed here in obs-rust by #1417, merged today with a regression test.
Script timers run on libobs's graphics thread while holding the scripting lock, and obs_frontend_set_current_scene() waited there for the UI thread. The UI thread, sending the scene change to the script's frontend event callback, waited for that same lock. Called from the graphics, audio or destroy thread, the scene change is now queued and the call returns; the scene changes right after, on the UI thread. Calls from any other thread, including obs-websocket's, still wait until the scene has changed.
Tested headless with a Lua script that has an event callback and calls obs_frontend_set_current_scene() from a 2 s timer. On 0.1.0-beta.20261018 the call never returned and OBS stopped answering. With the fix the call returns, the scene switches and OBS keeps responding, in 3 of 3 runs. Python script timers go through the same code (not tested separately).
It will be in the next obs-rust daily release after 0.1.0-beta.20261018: https://github.com/obs-rust/obs-studio/releases (Windows, macOS and Linux builds; on Arch it's obs-studio-rust-git in the AUR). obs-rust is an AI-assisted fork of OBS, based on current OBS master, with extra bug fixes like this one.
Activity
rdoupe commentedon Oct 18, 2026
Claiming: RED is a Tier 4 phase (
--only scripts) that runs the real app with a Lua script switching scenes from a timer; it fails on the release and on master. GREEN makesobs_frontend_set_current_scene()queue the change when called on a libobs thread. PR today.test: Add failing Tier 4 phase for a Lua timer that switches scenes
frontend: Queue scene changes that scripts make from a timer
frontend: Queue scene changes that scripts make from a timer (obs-rus…
rdoupe commentedon Oct 18, 2026
@woganmay you reported this in obsproject/obs-studio#3385: OBS hung when a script switched scenes from a timer. That's fixed here in obs-rust by #1417, merged today with a regression test.
Script timers run on libobs's graphics thread while holding the scripting lock, and
obs_frontend_set_current_scene()waited there for the UI thread. The UI thread, sending the scene change to the script's frontend event callback, waited for that same lock. Called from the graphics, audio or destroy thread, the scene change is now queued and the call returns; the scene changes right after, on the UI thread. Calls from any other thread, including obs-websocket's, still wait until the scene has changed.Tested headless with a Lua script that has an event callback and calls
obs_frontend_set_current_scene()from a 2 s timer. On 0.1.0-beta.20261018 the call never returned and OBS stopped answering. With the fix the call returns, the scene switches and OBS keeps responding, in 3 of 3 runs. Python script timers go through the same code (not tested separately).It will be in the next obs-rust daily release after 0.1.0-beta.20261018: https://github.com/obs-rust/obs-studio/releases (Windows, macOS and Linux builds; on Arch it's
obs-studio-rust-gitin the AUR). obs-rust is an AI-assisted fork of OBS, based on current OBS master, with extra bug fixes like this one.