From c4ba33dfebeb0abc6beb69ca048f87100834bb24 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Thu, 21 Apr 2011 02:04:15 +0200 Subject: [PATCH] server mutex fix --- common/server_game.cpp | 4 ++-- common/server_player.cpp | 10 +++++++++- common/server_player.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common/server_game.cpp b/common/server_game.cpp index 6a206bb7..a23c2bcb 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -51,7 +51,7 @@ Server_Game::~Server_Game() QMapIterator playerIterator(players); while (playerIterator.hasNext()) - delete playerIterator.next().value(); + playerIterator.next().value()->prepareDestroy(); players.clear(); room->removeGame(this); @@ -243,7 +243,7 @@ void Server_Game::removePlayer(Server_Player *player) sendGameEvent(new Event_Leave(player->getPlayerId())); bool playerActive = activePlayer == player->getPlayerId(); bool spectator = player->getSpectator(); - delete player; + player->prepareDestroy(); if (!getPlayerCount()) deleteLater(); diff --git a/common/server_player.cpp b/common/server_player.cpp index 9dd42eb5..0a6dc8ac 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -16,17 +16,25 @@ Server_Player::Server_Player(Server_Game *_game, int _playerId, ServerInfo_User } Server_Player::~Server_Player() +{ +} + +void Server_Player::prepareDestroy() { QMutexLocker locker(&game->gameMutex); - QMutexLocker locker2(&playerMutex); delete deck; + playerMutex.lock(); if (handler) handler->playerRemovedFromGame(game); + playerMutex.unlock(); + delete userInfo; clearZones(); + + deleteLater(); } void Server_Player::moveToThread(QThread *thread) diff --git a/common/server_player.h b/common/server_player.h index e0f7de49..955dd77c 100644 --- a/common/server_player.h +++ b/common/server_player.h @@ -43,6 +43,7 @@ private: public: Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler); ~Server_Player(); + void prepareDestroy(); void moveToThread(QThread *thread); Server_ProtocolHandler *getProtocolHandler() const { return handler; } void setProtocolHandler(Server_ProtocolHandler *_handler) { playerMutex.lock(); handler = _handler; playerMutex.unlock(); }