From 7dca2d76d65f3be6b55938201e200cb061d57b53 Mon Sep 17 00:00:00 2001 From: Oliver Benz Date: Sun, 1 Feb 2026 11:30:42 +0100 Subject: [PATCH] App,GUI: Proper shutdown of application. --- src/App/gameServer.cpp | 6 +++++- src/App/include/app/sessionManager.hpp | 1 + src/App/sessionManager.cpp | 16 ++++++++++++++++ src/gui/MainWindow.cpp | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/App/gameServer.cpp b/src/App/gameServer.cpp index 40c2294..316cbc9 100644 --- a/src/App/gameServer.cpp +++ b/src/App/gameServer.cpp @@ -31,13 +31,17 @@ void GameServer::start() { } void GameServer::stop() { + if (m_gameThread.joinable()) { + m_game.pushEvent(ShutdownEvent{}); + } + m_server.stop(); m_game.unsubscribeState(this); if (m_gameThread.joinable()) { - m_game.pushEvent(ShutdownEvent{}); m_gameThread.join(); } + m_players.clear(); } void GameServer::onClientConnected(gameNet::SessionId sessionId, gameNet::Seat seat) { diff --git a/src/App/include/app/sessionManager.hpp b/src/App/include/app/sessionManager.hpp index fdb64a0..086bfb3 100644 --- a/src/App/include/app/sessionManager.hpp +++ b/src/App/include/app/sessionManager.hpp @@ -35,6 +35,7 @@ class SessionManager : public gameNet::IClientHandler { void connect(const std::string& hostIp); void host(unsigned boardSize); void disconnect(); + void shutdown(); // Setters void tryPlace(unsigned x, unsigned y); diff --git a/src/App/sessionManager.cpp b/src/App/sessionManager.cpp index 66302ab..1aa9ba4 100644 --- a/src/App/sessionManager.cpp +++ b/src/App/sessionManager.cpp @@ -82,6 +82,22 @@ void SessionManager::disconnect() { m_eventHub.signal(AS_StateChange); } +void SessionManager::shutdown() { + if (m_localServer) { + m_localServer->stop(); + m_localServer.reset(); + } + m_network.disconnect(); + + { + std::lock_guard lock(m_stateMutex); + m_position.reset(9u); + m_expectedMessageId = 1u; + m_chatHistory.clear(); + m_pendingChat.clear(); + } +} + void SessionManager::tryPlace(unsigned x, unsigned y) { m_network.send(gameNet::ClientPutStone{.c = {x, y}}); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 0f03b5a..3e19038 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { // Setup Window setWindowTitle("Go Game"); setWindowFlags(windowFlags() | Qt::Tool | Qt::WindowStaysOnTopHint); + setAttribute(Qt::WA_QuitOnClose, true); buildLayout(); } @@ -49,6 +50,7 @@ void MainWindow::openHostDialog() { } void MainWindow::closeEvent(QCloseEvent* event) { + m_game.shutdown(); QMainWindow::closeEvent(event); }