mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Fix crash on OBS shutdown
This commit is contained in:
parent
0cd7004f6a
commit
a26c37021d
|
|
@ -25,6 +25,14 @@ SwitcherData::SwitcherData(obs_module_t *m, translateFunc t)
|
|||
_translate = t;
|
||||
}
|
||||
|
||||
SwitcherData::~SwitcherData()
|
||||
{
|
||||
// Assume that OBS is shutting down, as the switcher object will only be
|
||||
// destroyed when the plugin is unloaded
|
||||
obsIsShuttingDown = true;
|
||||
Stop();
|
||||
}
|
||||
|
||||
const char *SwitcherData::Translate(const char *text)
|
||||
{
|
||||
return _translate(text);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ std::unique_lock<std::mutex> *GetSwitcherLoopLock();
|
|||
|
||||
class SwitcherData {
|
||||
public:
|
||||
SwitcherData(obs_module_t *modulePtr, translateFunc translate);
|
||||
~SwitcherData();
|
||||
|
||||
void Thread();
|
||||
void Start();
|
||||
void Stop();
|
||||
|
|
@ -85,9 +88,6 @@ public:
|
|||
|
||||
/* --- End of saving / loading section --- */
|
||||
|
||||
SwitcherData(obs_module_t *m, translateFunc t);
|
||||
inline ~SwitcherData() { Stop(); }
|
||||
|
||||
public:
|
||||
SwitcherThread *th = nullptr;
|
||||
std::mutex m;
|
||||
|
|
@ -102,7 +102,7 @@ public:
|
|||
bool firstBoot = true;
|
||||
bool transitionActive = false;
|
||||
bool sceneColletionStop = false;
|
||||
bool obsIsShuttingDown = false;
|
||||
std::atomic_bool obsIsShuttingDown = {false};
|
||||
bool firstInterval = true;
|
||||
bool firstIntervalAfterStop = true;
|
||||
bool startupLoadDone = false;
|
||||
|
|
|
|||
|
|
@ -117,9 +117,25 @@ void RegisterWebsocketRequest(
|
|||
});
|
||||
}
|
||||
|
||||
static bool websocketModuleIsLoaded()
|
||||
{
|
||||
bool websocketModuleFound = false;
|
||||
const auto checkModule = [](void *param, obs_module_t *module) {
|
||||
bool *moduleFound = static_cast<bool *>(param);
|
||||
auto name = obs_get_module_name(module);
|
||||
if (name && strcmp(name, "obs-websocket") == 0) {
|
||||
*moduleFound = true;
|
||||
}
|
||||
};
|
||||
obs_enum_modules(checkModule, &websocketModuleFound);
|
||||
return websocketModuleFound;
|
||||
}
|
||||
|
||||
void SendWebsocketVendorEvent(const std::string &eventName, obs_data_t *data)
|
||||
{
|
||||
if (OBSIsShuttingDown()) {
|
||||
// If obs-websocket was loaded, but was unloaded at some point any calls
|
||||
// to obs_websocket_vendor_emit_event() will segfault
|
||||
if (OBSIsShuttingDown() || !websocketModuleIsLoaded()) {
|
||||
return;
|
||||
}
|
||||
obs_websocket_vendor_emit_event(vendor, eventName.c_str(), data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user