websocketserver: Check for EventHandler validity in de/constructor

Redundant fix for shutdown crash
This commit is contained in:
tt2468 2023-11-14 00:06:17 -08:00
parent efeae8d640
commit 07537a33fa

View File

@ -49,14 +49,21 @@ WebSocketServer::WebSocketServer() : QObject(nullptr)
websocketpp::lib::placeholders::_2));
auto eventHandler = GetEventHandler();
eventHandler->SetBroadcastCallback(std::bind(&WebSocketServer::BroadcastEvent, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
eventHandler->SetObsReadyCallback(std::bind(&WebSocketServer::onObsReady, this, std::placeholders::_1));
if (eventHandler) {
eventHandler->SetBroadcastCallback(std::bind(&WebSocketServer::BroadcastEvent, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
eventHandler->SetObsReadyCallback(std::bind(&WebSocketServer::onObsReady, this, std::placeholders::_1));
}
}
WebSocketServer::~WebSocketServer()
{
auto eventHandler = GetEventHandler();
if (eventHandler) {
eventHandler->SetObsReadyCallback(nullptr);
eventHandler->SetBroadcastCallback(nullptr);
}
if (_server.is_listening())
Stop();
}