From 87b69d67f88adeb3116b8434113550e01249a9bc Mon Sep 17 00:00:00 2001 From: FiniteSingularity Date: Mon, 7 Oct 2024 09:22:25 -0500 Subject: [PATCH 1/3] Fixes sporratic crash on load, and crash caused by ImageSlideshow sources. --- src/quick-access-source.cpp | 6 ++- src/quick-access-utility.cpp | 71 +++++++++++++++++++++++++----------- src/quick-access-utility.hpp | 2 + 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/quick-access-source.cpp b/src/quick-access-source.cpp index 4560f66..3fee6e3 100644 --- a/src/quick-access-source.cpp +++ b/src/quick-access-source.cpp @@ -364,11 +364,13 @@ QuickAccessSource::QuickAccessSource(obs_source_t *source) qRegisterMetaType(); } _source = obs_source_get_weak_source(source); - _tmpName = obs_source_get_name(source); + //_tmpName = obs_source_get_name(source); + _tmpName = "tmpname"; + const char* source_id = obs_source_get_id(source); + const char* source_type_name = obs_source_get_display_name(source_id); _sourceClass = obs_source_is_group(source) ? SourceClass::Group : obs_source_is_scene(source) ? SourceClass::Scene : SourceClass::Source; - blog(LOG_INFO, "====== Grabbed %s", _tmpName.c_str()); BuildSearchTerms(); } diff --git a/src/quick-access-utility.cpp b/src/quick-access-utility.cpp index 51b6d7a..ef726cb 100644 --- a/src/quick-access-utility.cpp +++ b/src/quick-access-utility.cpp @@ -26,7 +26,8 @@ QuickAccessSearchModal *QuickAccessSearchModal::dialog = nullptr; QuickAccessUtility::QuickAccessUtility(obs_module_t *m) : _module(m), _firstRun(false), - _currentScene(nullptr) + _currentScene(nullptr), + _dockSettings(nullptr) { obs_frontend_add_event_callback(QuickAccessUtility::FrontendCallback, this); @@ -53,6 +54,9 @@ void QuickAccessUtility::SourceCreated(void *data, calldata_t *params) UNUSED_PARAMETER(data); obs_source_t *source = static_cast(calldata_ptr(params, "source")); + if (obs_obj_is_private(source)) { + return; + } std::string uuid = obs_source_get_uuid(source); QuickAccessUtility::AddSource(nullptr, source); if (qau->_allSources.count(uuid) == 0) { @@ -167,15 +171,7 @@ void QuickAccessUtility::Load(obs_data_t *data) std::unique_lock lock(_m); RemoveDocks(); _allSources.clear(); - // Add Scenes and sources to _allSources - obs_enum_all_sources(QuickAccessUtility::AddSource, qau); - obs_enum_scenes(QuickAccessUtility::AddSource, qau); - // Link scenes/groups with their children - obs_enum_scenes(QuickAccessUtility::LinkScenes, qau); - - const auto mainWindow = - static_cast(obs_frontend_get_main_window()); auto qauData = obs_data_get_obj(data, "quick_access_utility"); if (!qauData) { qauData = obs_data_create(); @@ -185,14 +181,7 @@ void QuickAccessUtility::Load(obs_data_t *data) obs_data_array_release(docks); } _firstRun = obs_data_get_bool(qauData, "first_run"); - auto docks = obs_data_get_array(qauData, "docks"); - for (size_t i = 0; i < obs_data_array_count(docks); i++) { - auto dockData = obs_data_array_item(docks, i); - auto d = new QuickAccessDock(mainWindow, dockData); - _docks.push_back(d); - obs_data_release(dockData); - } - obs_data_array_release(docks); + _dockSettings = obs_data_get_array(qauData, "docks"); auto quickSearchHotkey = obs_data_get_array(qauData, "quick_search_hotkey"); @@ -201,18 +190,40 @@ void QuickAccessUtility::Load(obs_data_t *data) obs_data_release(qauData); + //loaded = true; +} + +void QuickAccessUtility::_SetupDocks() +{ + std::unique_lock lock(_m); + + // Add Scenes and sources to _allSources + obs_enum_all_sources(QuickAccessUtility::AddSource, qau); + obs_enum_scenes(QuickAccessUtility::AddSource, qau); + + // Link scenes/groups with their children + obs_enum_scenes(QuickAccessUtility::LinkScenes, qau); + + const auto mainWindow = + static_cast(obs_frontend_get_main_window()); + + for (size_t i = 0; i < obs_data_array_count(_dockSettings); i++) { + auto dockData = obs_data_array_item(_dockSettings, i); + auto d = new QuickAccessDock(mainWindow, dockData); + _docks.push_back(d); + obs_data_release(dockData); + } + obs_data_array_release(_dockSettings); + // Set up the quick search dialog // This shouldn't need to be done, but for some reason // the first time we pop open the search, it is a tiny // window and then disappears. if (!QuickAccessSearchModal::dialog) { - const auto main_window = static_cast( - obs_frontend_get_main_window()); - const QRect &hostRect = main_window->geometry(); + const QRect& hostRect = mainWindow->geometry(); QuickAccessSearchModal::dialog = - new QuickAccessSearchModal(static_cast( - obs_frontend_get_main_window())); + new QuickAccessSearchModal(mainWindow); auto searchDlg = QuickAccessSearchModal::dialog; searchDlg->open(); searchDlg->move(hostRect.center() - searchDlg->rect().center()); @@ -348,7 +359,9 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event, { UNUSED_PARAMETER(data); if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) { + blog(LOG_INFO, "======== OBS_FRONTEND_EVENT_FINISHED_LOADING called."); qau->_sceneCollectionChanging = false; + qau->_SetupDocks(); qau->_SetupSignals(); qau->SceneChanged(); } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP) { @@ -361,7 +374,9 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event, qau->_TearDownSignals(); qau->_sceneCollectionChanging = true; } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) { + blog(LOG_INFO, "======== OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED called."); qau->_sceneCollectionChanging = false; + qau->_SetupDocks(); qau->_SetupSignals(); qau->InitializeSearch(); qau->SceneChanged(); @@ -584,6 +599,17 @@ bool QuickAccessUtility::AddSource(void *data, obs_source_t *source) return true; } std::string uuid = obs_source_get_uuid(source); + + bool priv = obs_obj_is_private(source); + + const char* source_id = obs_source_get_id(source); + const char* source_type_name = obs_source_get_display_name(source_id); + const char* source_name = obs_source_get_name(source); + std::string name = source_name ? source_name : "NULL NAME"; + + if (priv) + return true; + if (qau->_allSources.find(uuid) == qau->_allSources.end()) { qau->_allSources.emplace( uuid, std::make_unique(source)); @@ -1117,6 +1143,7 @@ extern "C" EXPORT void CheckModules() void frontendSaveLoad(obs_data_t *save_data, bool saving, void *data) { + blog(LOG_INFO, "======== obs_frontend_save_load_callback called."); auto quickAccessUtility = static_cast(data); if (saving) { quickAccessUtility->Save(save_data); diff --git a/src/quick-access-utility.hpp b/src/quick-access-utility.hpp index a3f82e3..88c794f 100644 --- a/src/quick-access-utility.hpp +++ b/src/quick-access-utility.hpp @@ -93,6 +93,7 @@ class QuickAccessUtility { void _TearDownSignals(); void _SetCurrentSceneSources(); void _AddChildren(QuickAccessSource *scene); + void _SetupDocks(); obs_module_t *_module = nullptr; std::vector _docks; @@ -103,6 +104,7 @@ class QuickAccessUtility { bool _sceneCollectionChanging = true; bool _sourceCloneInstalled = false; bool _dskInstalled = false; + obs_data_array_t* _dockSettings; obs_hotkey_id _quick_search_hotkey_id; From 8cb15ca445708b8462630426d7e7e53793baf7e6 Mon Sep 17 00:00:00 2001 From: FiniteSingularity Date: Mon, 7 Oct 2024 10:01:24 -0500 Subject: [PATCH 2/3] Fixes formatting. --- src/quick-access-source.cpp | 5 +---- src/quick-access-utility.cpp | 27 +++++++++++++-------------- src/quick-access-utility.hpp | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/quick-access-source.cpp b/src/quick-access-source.cpp index 3fee6e3..7f262f3 100644 --- a/src/quick-access-source.cpp +++ b/src/quick-access-source.cpp @@ -364,10 +364,7 @@ QuickAccessSource::QuickAccessSource(obs_source_t *source) qRegisterMetaType(); } _source = obs_source_get_weak_source(source); - //_tmpName = obs_source_get_name(source); - _tmpName = "tmpname"; - const char* source_id = obs_source_get_id(source); - const char* source_type_name = obs_source_get_display_name(source_id); + _tmpName = obs_source_get_name(source); _sourceClass = obs_source_is_group(source) ? SourceClass::Group : obs_source_is_scene(source) ? SourceClass::Scene : SourceClass::Source; diff --git a/src/quick-access-utility.cpp b/src/quick-access-utility.cpp index ef726cb..26b44b7 100644 --- a/src/quick-access-utility.cpp +++ b/src/quick-access-utility.cpp @@ -205,7 +205,7 @@ void QuickAccessUtility::_SetupDocks() obs_enum_scenes(QuickAccessUtility::LinkScenes, qau); const auto mainWindow = - static_cast(obs_frontend_get_main_window()); + static_cast(obs_frontend_get_main_window()); for (size_t i = 0; i < obs_data_array_count(_dockSettings); i++) { auto dockData = obs_data_array_item(_dockSettings, i); @@ -220,7 +220,7 @@ void QuickAccessUtility::_SetupDocks() // the first time we pop open the search, it is a tiny // window and then disappears. if (!QuickAccessSearchModal::dialog) { - const QRect& hostRect = mainWindow->geometry(); + const QRect &hostRect = mainWindow->geometry(); QuickAccessSearchModal::dialog = new QuickAccessSearchModal(mainWindow); @@ -359,7 +359,8 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event, { UNUSED_PARAMETER(data); if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) { - blog(LOG_INFO, "======== OBS_FRONTEND_EVENT_FINISHED_LOADING called."); + blog(LOG_INFO, + "======== OBS_FRONTEND_EVENT_FINISHED_LOADING called."); qau->_sceneCollectionChanging = false; qau->_SetupDocks(); qau->_SetupSignals(); @@ -374,7 +375,8 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event, qau->_TearDownSignals(); qau->_sceneCollectionChanging = true; } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) { - blog(LOG_INFO, "======== OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED called."); + blog(LOG_INFO, + "======== OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED called."); qau->_sceneCollectionChanging = false; qau->_SetupDocks(); qau->_SetupSignals(); @@ -594,21 +596,18 @@ bool QuickAccessUtility::AddSource(void *data, obs_source_t *source) { UNUSED_PARAMETER(data); + bool priv = obs_obj_is_private(source); + + if (priv) { + return true; + } + obs_source_type st = obs_source_get_type(source); if (st == OBS_SOURCE_TYPE_FILTER || st == OBS_SOURCE_TYPE_TRANSITION) { return true; } - std::string uuid = obs_source_get_uuid(source); - - bool priv = obs_obj_is_private(source); - const char* source_id = obs_source_get_id(source); - const char* source_type_name = obs_source_get_display_name(source_id); - const char* source_name = obs_source_get_name(source); - std::string name = source_name ? source_name : "NULL NAME"; - - if (priv) - return true; + std::string uuid = obs_source_get_uuid(source); if (qau->_allSources.find(uuid) == qau->_allSources.end()) { qau->_allSources.emplace( diff --git a/src/quick-access-utility.hpp b/src/quick-access-utility.hpp index 88c794f..fbefc0b 100644 --- a/src/quick-access-utility.hpp +++ b/src/quick-access-utility.hpp @@ -104,7 +104,7 @@ class QuickAccessUtility { bool _sceneCollectionChanging = true; bool _sourceCloneInstalled = false; bool _dskInstalled = false; - obs_data_array_t* _dockSettings; + obs_data_array_t *_dockSettings; obs_hotkey_id _quick_search_hotkey_id; From 1e2b87494f31876015a83611de7cdccb70cdcc97 Mon Sep 17 00:00:00 2001 From: FiniteSingularity Date: Mon, 7 Oct 2024 16:34:05 -0500 Subject: [PATCH 3/3] Code cleanup. --- src/quick-access-dock.cpp | 18 +++++++++--------- src/quick-access-utility.cpp | 16 +++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/quick-access-dock.cpp b/src/quick-access-dock.cpp index 739629e..2137958 100644 --- a/src/quick-access-dock.cpp +++ b/src/quick-access-dock.cpp @@ -233,9 +233,10 @@ void QuickAccessDock::DrawDock(obs_data_t *obsData) const auto d = static_cast(parentWidget()); - const auto floating = obs_data_get_bool(obsData, "dock_floating"); - if (d->isFloating() != floating) { - d->setFloating(floating); + if (obs_data_get_bool(obsData, "dock_hidden")) { + d->hide(); + } else { + d->show(); } const auto area = static_cast( @@ -244,17 +245,16 @@ void QuickAccessDock::DrawDock(obs_data_t *obsData) mainWindow->addDockWidget(area, d); } + const auto floating = obs_data_get_bool(obsData, "dock_floating"); + if (d->isFloating() != floating) { + d->setFloating(floating); + } + const char *geometry = obs_data_get_string(obsData, "dock_geometry"); if (geometry && strlen(geometry)) { d->restoreGeometry( QByteArray::fromBase64(QByteArray(geometry))); } - - if (obs_data_get_bool(obsData, "dock_hidden")) { - d->hide(); - } else { - d->show(); - } } void QuickAccessDock::Save(obs_data_t *obsData) diff --git a/src/quick-access-utility.cpp b/src/quick-access-utility.cpp index 26b44b7..1f32ffc 100644 --- a/src/quick-access-utility.cpp +++ b/src/quick-access-utility.cpp @@ -183,6 +183,8 @@ void QuickAccessUtility::Load(obs_data_t *data) _firstRun = obs_data_get_bool(qauData, "first_run"); _dockSettings = obs_data_get_array(qauData, "docks"); + _SetupDocks(); + auto quickSearchHotkey = obs_data_get_array(qauData, "quick_search_hotkey"); obs_hotkey_load(_quick_search_hotkey_id, quickSearchHotkey); @@ -195,7 +197,7 @@ void QuickAccessUtility::Load(obs_data_t *data) void QuickAccessUtility::_SetupDocks() { - std::unique_lock lock(_m); + //std::unique_lock lock(_m); // Add Scenes and sources to _allSources obs_enum_all_sources(QuickAccessUtility::AddSource, qau); @@ -362,7 +364,7 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event, blog(LOG_INFO, "======== OBS_FRONTEND_EVENT_FINISHED_LOADING called."); qau->_sceneCollectionChanging = false; - qau->_SetupDocks(); + //qau->_SetupDocks(); qau->_SetupSignals(); qau->SceneChanged(); } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP) { @@ -378,7 +380,7 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event, blog(LOG_INFO, "======== OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED called."); qau->_sceneCollectionChanging = false; - qau->_SetupDocks(); + //qau->_SetupDocks(); qau->_SetupSignals(); qau->InitializeSearch(); qau->SceneChanged(); @@ -597,13 +599,9 @@ bool QuickAccessUtility::AddSource(void *data, obs_source_t *source) UNUSED_PARAMETER(data); bool priv = obs_obj_is_private(source); - - if (priv) { - return true; - } - obs_source_type st = obs_source_get_type(source); - if (st == OBS_SOURCE_TYPE_FILTER || st == OBS_SOURCE_TYPE_TRANSITION) { + if (priv || st == OBS_SOURCE_TYPE_FILTER || + st == OBS_SOURCE_TYPE_TRANSITION) { return true; }