diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 235bd6ed7..c8cf13f89 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -415,6 +415,30 @@ void OBSBasic::LoadSceneListOrder(obs_data_array_t *array) } } +void OBSBasic::CleanupUnusedSources() +{ + auto removeUnusedSources = [&](obs_source_t *source) + { + obs_scene_t *scene = obs_scene_from_source(source); + if (scene) + return; + + if (sourceSceneRefs[source] == 0) { + sourceSceneRefs.erase(source); + obs_source_remove(source); + } + }; + using func_type = decltype(removeUnusedSources); + + obs_enum_sources( + [](void *f, obs_source_t *source) + { + (*static_cast(f))(source); + return true; + }, + static_cast(&removeUnusedSources)); +} + void OBSBasic::Load(const char *file) { if (!file) { @@ -478,6 +502,8 @@ void OBSBasic::Load(const char *file) obs_data_release(data); + CleanupUnusedSources(); + disableSaving--; } diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index e81f3d5e6..69785fcb3 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -163,6 +163,7 @@ private: void CloseDialogs(); void ClearSceneData(); + void CleanupUnusedSources(); void Nudge(int dist, MoveDir dir); void OpenProjector(obs_source_t *source, int monitor);