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)); websocketpp::lib::placeholders::_2));
auto eventHandler = GetEventHandler(); auto eventHandler = GetEventHandler();
if (eventHandler) {
eventHandler->SetBroadcastCallback(std::bind(&WebSocketServer::BroadcastEvent, this, std::placeholders::_1, eventHandler->SetBroadcastCallback(std::bind(&WebSocketServer::BroadcastEvent, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
eventHandler->SetObsReadyCallback(std::bind(&WebSocketServer::onObsReady, this, std::placeholders::_1)); eventHandler->SetObsReadyCallback(std::bind(&WebSocketServer::onObsReady, this, std::placeholders::_1));
}
} }
WebSocketServer::~WebSocketServer() WebSocketServer::~WebSocketServer()
{ {
auto eventHandler = GetEventHandler();
if (eventHandler) {
eventHandler->SetObsReadyCallback(nullptr);
eventHandler->SetBroadcastCallback(nullptr);
}
if (_server.is_listening()) if (_server.is_listening())
Stop(); Stop();
} }