Fix crash on OBS shutdown

This commit is contained in:
WarmUpTill 2025-07-05 18:22:45 +02:00
parent 0cd7004f6a
commit a26c37021d
3 changed files with 29 additions and 5 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);