From 9f6f6d632bae3ba31b9cb00bd1ef64173a1b8fd0 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 6 Jul 2015 18:50:16 -0700 Subject: [PATCH] UI: Remove all unused user sources on load This temporarily fixes an issue where potential (for whatever reason) stray sources that aren't associated with any scenes could be saved and then persist with the save data on load. --- obs/window-basic-main.cpp | 26 ++++++++++++++++++++++++++ obs/window-basic-main.hpp | 1 + 2 files changed, 27 insertions(+) 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);