From ab2762ebd30203e03c35083cc79a557a5d9a2a70 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Wed, 29 Apr 2026 14:17:52 +0200 Subject: [PATCH] Cleanup --- lib/advanced-scene-switcher.cpp | 6 +++--- lib/utils/crash-handler.cpp | 7 ++++--- lib/variables/variable.cpp | 23 ++++++++++------------- plugins/twitch/event-sub.cpp | 13 +++++++------ 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/advanced-scene-switcher.cpp b/lib/advanced-scene-switcher.cpp index 0c94b142..24f2fb31 100644 --- a/lib/advanced-scene-switcher.cpp +++ b/lib/advanced-scene-switcher.cpp @@ -629,7 +629,7 @@ static void handleSceneCollectionCleanup() // OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP is also called on // shutdown. - // Here we also don't want to reload the settings. + // Here we also don't want to clear the settings. if (switcher->obsIsShuttingDown) { return; } @@ -640,7 +640,7 @@ static void handleSceneCollectionCleanup() // Note to future self: // be careful using switcher->m here as there is potential for deadlocks when using // frontend functions such as obs_frontend_set_current_scene() -static void OBSEvent(enum obs_frontend_event event, void *switcher) +static void OBSEvent(enum obs_frontend_event event, void *) { if (!switcher) { return; @@ -792,7 +792,7 @@ extern "C" EXPORT void InitSceneSwitcher(obs_module_t *module, RunPluginInitSteps(); obs_frontend_add_save_callback(SaveSceneSwitcher, nullptr); - obs_frontend_add_event_callback(OBSEvent, switcher); + obs_frontend_add_event_callback(OBSEvent, nullptr); QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction( obs_module_text("AdvSceneSwitcher.pluginName")); diff --git a/lib/utils/crash-handler.cpp b/lib/utils/crash-handler.cpp index 676cda44..c17c5d5a 100644 --- a/lib/utils/crash-handler.cpp +++ b/lib/utils/crash-handler.cpp @@ -28,6 +28,8 @@ static constexpr bool handleUncleanShutdown = true; static bool wasCleanShutdown = false; static bool suppressCrashDialog = false; +static char *sentinelFile = nullptr; + bool GetSuppressCrashDialog() { return suppressCrashDialog; @@ -58,7 +60,6 @@ static void handleShutdown(enum obs_frontend_event event, void *) return; } - char *sentinelFile = obs_module_config_path(sentinel.data()); if (!sentinelFile) { return; } @@ -78,7 +79,8 @@ static void handleShutdown(enum obs_frontend_event event, void *) static void setup() { - char *sentinelFile = obs_module_config_path(sentinel.data()); + // Freed in handleShutdown() + sentinelFile = obs_module_config_path(sentinel.data()); if (!sentinelFile) { return; } @@ -106,7 +108,6 @@ static void setup() file.write("running"); file.close(); - bfree(sentinelFile); obs_frontend_add_event_callback(handleShutdown, nullptr); return; diff --git a/lib/variables/variable.cpp b/lib/variables/variable.cpp index a752b888..d99b49bc 100644 --- a/lib/variables/variable.cpp +++ b/lib/variables/variable.cpp @@ -4,6 +4,8 @@ #include "ui-helpers.hpp" #include "utility.hpp" +#include + #include namespace advss { @@ -418,34 +420,32 @@ static bool variableWithNameExists(const std::string &name) void SaveVariables(obs_data_t *obj) { - obs_data_array_t *variablesArray = obs_data_array_create(); + OBSDataArrayAutoRelease variablesArray = obs_data_array_create(); for (const auto &v : variables) { - obs_data_t *array_obj = obs_data_create(); + OBSDataAutoRelease array_obj = obs_data_create(); v->Save(array_obj); obs_data_array_push_back(variablesArray, array_obj); - obs_data_release(array_obj); } obs_data_set_array(obj, "variables", variablesArray); - obs_data_array_release(variablesArray); } void LoadVariables(obs_data_t *obj) { variables.clear(); - obs_data_array_t *variablesArray = obs_data_get_array(obj, "variables"); + OBSDataArrayAutoRelease variablesArray = + obs_data_get_array(obj, "variables"); size_t count = obs_data_array_count(variablesArray); for (size_t i = 0; i < count; i++) { - obs_data_t *array_obj = obs_data_array_item(variablesArray, i); + OBSDataAutoRelease array_obj = + obs_data_array_item(variablesArray, i); auto var = Variable::Create(); variables.emplace_back(var); variables.back()->Load(array_obj); obs_data_release(array_obj); } - - obs_data_array_release(variablesArray); } static void signalImportedVariables(void *varsPtr) @@ -460,16 +460,15 @@ static void signalImportedVariables(void *varsPtr) void ImportVariables(obs_data_t *data) { - obs_data_array_t *array = obs_data_get_array(data, "variables"); + OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables"); size_t count = obs_data_array_count(array); auto importedVars = new std::vector>; for (size_t i = 0; i < count; i++) { - obs_data_t *arrayElement = obs_data_array_item(array, i); + OBSDataAutoRelease arrayElement = obs_data_array_item(array, i); auto var = Variable::Create(); var->Load(arrayElement); - obs_data_release(arrayElement); if (variableWithNameExists(var->Name())) { continue; @@ -479,8 +478,6 @@ void ImportVariables(obs_data_t *data) importedVars->emplace_back(var); } - obs_data_array_release(array); - QueueUITask(signalImportedVariables, importedVars); } diff --git a/plugins/twitch/event-sub.cpp b/plugins/twitch/event-sub.cpp index 5f13fff5..9bd308b3 100644 --- a/plugins/twitch/event-sub.cpp +++ b/plugins/twitch/event-sub.cpp @@ -8,6 +8,8 @@ #include "date/tz.h" #endif +using namespace std::chrono_literals; + namespace advss { using websocketpp::lib::placeholders::_1; @@ -28,7 +30,7 @@ static constexpr std::string_view registerSubscriptionURL = static constexpr std::string_view registerSubscriptionPath = "/helix/eventsub/subscriptions"; #endif -static const int reconnectDelay = 15; +static const auto reconnectDelay = 15s; #undef DispatchMessage @@ -98,9 +100,9 @@ void EventSub::WaitAndReconnect() auto thread = std::thread([this]() { std::unique_lock lock(_waitMtx); blog(LOG_INFO, - "Twitch EventSub trying to reconnect to in %d seconds.", - reconnectDelay); - _cv.wait_for(lock, std::chrono::seconds(reconnectDelay)); + "Twitch EventSub trying to reconnect to in %lld seconds.", + (long long)reconnectDelay.count()); + _cv.wait_for(lock, reconnectDelay); _reconnecting = false; if (_disconnect) { @@ -342,8 +344,7 @@ static bool isValidTimestamp(const std::string ×tamp) auto duration = now - parsedTime; // Clocks might be off by a bit, so allow negative values also - return duration <= std::chrono::minutes(10) && - duration >= std::chrono::minutes(-1); + return duration <= 10min && duration >= -1min; } catch (const std::exception &e) { blog(LOG_WARNING, "%s: %s", __func__, e.what()); return false;