Error "Attempted to insert context with duplicate name"

adaendra

New Member
Hi,

I have a script which automatically change scene in Python, but when I change the scene collection and come back to the one with my script, I have the following error :
16:58:15.517: Attempted to insert context with duplicate name "DQ9withScriptSwitch"! Name has been changed to "DQ9withScriptSwitch 2"
16:58:15.517: Attempted to insert context with duplicate UUID "c5e82895-5d5b-4a67-af15-50c2991daf50"!

Here is my script
import obspython as obs
import getpixelcolor
import time

def script_description():
# Description du script qui sera affiché dans OBS
return "Pour changer automatiquement de scènes"

def script_load(settings):
print("load 11")
# Appelle la fonction "update_scenes", avec un paramètre en ms
obs.timer_add(update_scenes, 500)

obs.obs_frontend_add_event_callback(on_event)

def on_event(event):
print(event)
if event == obs.OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING:
print("OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING")

obs.obs_frontend_remove_event_callback(on_event)
obs.timer_remove(update_scenes)
time.sleep(3)
stream_scene = obs.obs_get_scene_by_name("DQ9withScriptSwitch")
fighting_scene = obs.obs_scene_find_source(stream_scene, "speedrun (haut)")
other_scene = obs.obs_scene_find_source(stream_scene, "speedrun (bas)")
obs.obs_scene_release(stream_scene)
obs.obs_sceneitem_release(fighting_scene)
obs.obs_sceneitem_release(other_scene)
time.sleep(3)

print("--->sOBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING")

def update_scenes():
print('coucou')
# OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING - https://docs.obsproject.com/reference-frontend-api?highlight=paused#functions
# Récupère la scène par son nom (ici stream_scene)
stream_scene = obs.obs_get_scene_by_name("DQ9withScriptSwitch")

is_fight = (getpixelcolor.average(97, 303, 200, 5) == (182, 120, 59))

# Récupère l'item dans la scène stream_scene portant le nom fighting_scene
fighting_scene = obs.obs_scene_find_source(stream_scene, "speedrun (haut)")
# Switch la visibilité de l'item fighting_scene (false <-> true)
obs.obs_sceneitem_set_visible(fighting_scene, is_fight)

# Récupère l'item dans la scène stream_scene portant le nom other_scene
other_scene = obs.obs_scene_find_source(stream_scene, "speedrun (bas)")
# Switch la visibilité de l'item other_scene (false <-> true)
obs.obs_sceneitem_set_visible(other_scene, not is_fight)

Do you have any idea about what can generate this ? or a way to clear the context please?

Thanks for your help
 
Top