scenes = obs.obs_frontend_get_scenes()
def script_load(settings):
obs.obs_frontend_add_event_callback(onevent)
def script_update(settings):
global trigger, s_minutes, s_seconds, ending, e_minutes, e_seconds
trigger = obs.obs_data_get_string(settings, "e_trigger scene")
s_minutes = obs.obs_data_get_int(settings, "s_minutes")
s_seconds = obs.obs_data_get_int(settings, "s_seconds")
e_minutes = obs.obs_data_get_int(settings, "e_minutes")
e_seconds = obs.obs_data_get_int(settings, "e_seconds")
ending = obs.obs_data_get_string(settings, "s_ending scene")
def timer_callback():
global tElapsed
if state == 0:
print("Error: State = 0")
obs.remove_current_callback()
if state == 1:
tElapsed += 1
print(tElapsed)
if tElapsed == timer:
tElapsed = 0
set_scene()
obs.remove_current_callback()
if state == 2:
tElapsed += 1
print(tElapsed)
if tElapsed == timer:
tElapsed = 0
obs.obs_frontend_streaming_stop()
obs.remove_current_callback()
def set_scene():
index = (obs.obs_frontend_get_scene_names()).index(ending)
scene = scenes[index]
obs.obs_frontend_set_current_scene(scene)
def onevent(event):
global state, timer
if event==obs.OBS_FRONTEND_EVENT_STREAMING_STOPPED:
state = 0
if event==obs.OBS_FRONTEND_EVENT_STREAMING_STARTED:
state = 1
timer = s_minutes * 60 + s_seconds
obs.timer_add(timer_callback,1000)
if event==obs.OBS_FRONTEND_EVENT_SCENE_CHANGED:
if obs.obs_source_get_name(obs.obs_frontend_get_current_scene()) == trigger:
state = 2
timer = e_minutes * 60 + e_seconds
obs.timer_add(timer_callback,1000)
else:
obs.timer_remove(timer_callback)
if state == 1:
print("Start timer stopped")
elif state == 2:
print("End timer stopped")
When I try to set the scene from within a timer callback function, OBS ends up crashing. I've tried to print the number for every time the callback function is called, and when I look at the logs, it shows every print function it's supposed to call, but it doesn't tell me why OBS crashed.
This is the code where I use a helper function to set the scene. With or without the helper function, it crashes either way. However, when I set the scene from outside the timer, everything works fine.
Any form of help is appreciated!