From 07537a33faff62b6cb8202b5369720bf2a52d8b6 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 14 Nov 2023 00:06:17 -0800 Subject: [PATCH] websocketserver: Check for EventHandler validity in de/constructor Redundant fix for shutdown crash --- src/websocketserver/WebSocketServer.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/websocketserver/WebSocketServer.cpp b/src/websocketserver/WebSocketServer.cpp index 107a124e5..fdea4e801 100644 --- a/src/websocketserver/WebSocketServer.cpp +++ b/src/websocketserver/WebSocketServer.cpp @@ -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(); }