mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-05-06 04:47:08 -05:00
Deregister all inline scripts on SCRIPTING_SHUTDOWN
This commit is contained in:
parent
6a3de18069
commit
4bfd40219b
|
|
@ -2,9 +2,13 @@
|
|||
#include "log-helper.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
#include <obs-module.h>
|
||||
#include <obs.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
|
@ -28,6 +32,17 @@ const std::string_view InlineScript::_defaultLUAScript =
|
|||
"end";
|
||||
;
|
||||
|
||||
static std::mutex instancesMutex;
|
||||
static std::unordered_set<InlineScript *> instances;
|
||||
|
||||
static void handleScriptingShutdown(enum obs_frontend_event event, void *)
|
||||
{
|
||||
if (event != OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN) {
|
||||
return;
|
||||
}
|
||||
InlineScript::DeregisterAll();
|
||||
}
|
||||
|
||||
static bool setup()
|
||||
{
|
||||
auto sh = obs_get_signal_handler();
|
||||
|
|
@ -35,6 +50,8 @@ static bool setup()
|
|||
std::string("void ") + signalName.data() + "(string id)";
|
||||
signal_handler_add(sh, signalDecl.c_str());
|
||||
|
||||
obs_frontend_add_event_callback(handleScriptingShutdown, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
static bool setupDone = setup();
|
||||
|
|
@ -98,6 +115,10 @@ static bool createScriptFile(const char *settingsFile, const char *content)
|
|||
|
||||
InlineScript::InlineScript() : _instanceId(_instanceIdCounter++)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(instancesMutex);
|
||||
instances.insert(this);
|
||||
}
|
||||
Setup();
|
||||
}
|
||||
|
||||
|
|
@ -107,9 +128,27 @@ InlineScript::InlineScript(const InlineScript &other)
|
|||
_textLUA(other._textLUA),
|
||||
_instanceId(_instanceIdCounter++)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(instancesMutex);
|
||||
instances.insert(this);
|
||||
}
|
||||
Setup();
|
||||
}
|
||||
|
||||
InlineScript::~InlineScript()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(instancesMutex);
|
||||
instances.erase(this);
|
||||
}
|
||||
|
||||
void InlineScript::DeregisterAll()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(instancesMutex);
|
||||
for (auto *instance : instances) {
|
||||
instance->_script.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void InlineScript::Save(obs_data_t *data) const
|
||||
{
|
||||
OBSDataAutoRelease obj = obs_data_create();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class InlineScript {
|
|||
public:
|
||||
InlineScript();
|
||||
InlineScript(const InlineScript &);
|
||||
~InlineScript();
|
||||
|
||||
enum Type { INLINE, FILE };
|
||||
|
||||
|
|
@ -34,6 +35,8 @@ public:
|
|||
|
||||
void ResolveVariablesToFixedValues();
|
||||
|
||||
static void DeregisterAll();
|
||||
|
||||
private:
|
||||
void Setup();
|
||||
void SetupFile();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user