LUA scripting - releasing the list from obs_frontend_get_scenes

SN1974

New Member
I am working on a LUA script which will show or hide a source in all scenes that the source appears in. Thanks to some help from another user I found the obs_frontend_get_scenes function. Since the API docs indicate that the list needs to be released I included the line obs.obs_frontend_source_list_free(colScenes) before the function completes. This throws a script error

Failed to call frontend_event_callback for frontend API: C:/Users/User/Desktop/AutoSongChanger.lua:111: attempt to call field 'obs_frontend_source_list_free' (a nil value)

If I remove the release call, my custom function works as intended - except I get a crash in OBS websockets when I close OBS.

Here is my entire function

function fSetSourceStateInAllScenes(bolVisibility)
local colScenes = obs.obs_frontend_get_scenes()
local objScene
local strSceneName
local sceneitems
local sceneitem
for _, objScene in ipairs(colScenes) do
local scene_source = obs.obs_scene_from_source(objScene)
sceneitems = obs.obs_scene_enum_items(scene_source)
for _, sceneitem in ipairs(sceneitems) do
local itemsource = obs.obs_sceneitem_get_source(sceneitem)
local isn = obs.obs_source_get_name(itemsource)
if strSourceName == isn then
obs.obs_sceneitem_set_visible(sceneitem, bolVisibility)
end
end
obs.sceneitem_list_release(sceneitems)
end
obs.obs_frontend_source_list_free(colScenes)
end

I hope someone can help find what I'm doing wrong.

Thanks
SN1974
 

SN1974

New Member
Finally found the answer - the correct way to release obs_frontend_get_scenes() in script is with source_list_release(). Might I suggest someone update the documentation to reflect this difference?
 
Top