Skip to content

Commit

Permalink
websocketserver: Check for EventHandler validity in de/constructor
Browse files Browse the repository at this point in the history
Redundant fix for shutdown crash
  • Loading branch information
tt2468 committed Nov 14, 2023
1 parent efeae8d commit 07537a3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/websocketserver/WebSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 07537a3

Please sign in to comment.