From 06321f89e1bf7ecd04efd3c9ebc4229b44b98c5a Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Sun, 28 Jun 2020 01:49:57 +0200 Subject: [PATCH] UI: Remove OBSContext class and shutdown in run_program The OBSContext never called obs_startup but would always call obs_shutdown in its destructor, resulting in shutdown calls even if libobs wasn't initialized (eg due to a startup error). Instead, we now track if libobs was initialized in OBSApp and call shutdown in the destructor. --- UI/obs-app.cpp | 5 +++++ UI/obs-app.hpp | 3 ++- libobs/obs.hpp | 13 ------------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index c33afa3de..83d0a2ec3 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -1131,6 +1131,9 @@ OBSApp::~OBSApp() os_inhibit_sleep_set_active(sleepInhibitor, false); os_inhibit_sleep_destroy(sleepInhibitor); + + if (libobs_initialized) + obs_shutdown(); } static void move_basic_to_profiles(void) @@ -1352,6 +1355,8 @@ bool OBSApp::OBSInit() if (!StartupOBS(locale.c_str(), GetProfilerNameStore())) return false; + libobs_initialized = true; + obs_set_ui_task_handler(ui_task_handler); #ifdef _WIN32 diff --git a/UI/obs-app.hpp b/UI/obs-app.hpp index 3fbff32a1..e10ea6bdd 100644 --- a/UI/obs-app.hpp +++ b/UI/obs-app.hpp @@ -72,10 +72,11 @@ private: std::string theme; ConfigFile globalConfig; TextLookup textLookup; - OBSContext obsContext; QPointer mainWindow; profiler_name_store_t *profilerNameStore = nullptr; + bool libobs_initialized = false; + os_inhibit_t *sleepInhibitor = nullptr; int sleepInhibitRefs = 0; diff --git a/libobs/obs.hpp b/libobs/obs.hpp index 97d2e15cb..2c5929042 100644 --- a/libobs/obs.hpp +++ b/libobs/obs.hpp @@ -266,16 +266,3 @@ public: return *this; } }; - -class OBSContext { -public: - inline OBSContext() {} - inline OBSContext(const char *locale, - const char *module_config_path = nullptr, - profiler_name_store *store = nullptr) - { - obs_startup(locale, module_config_path, store); - } - - inline ~OBSContext() { obs_shutdown(); } -};