Commit c4ba33df authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

server mutex fix

parent 38b31681
......@@ -51,7 +51,7 @@ Server_Game::~Server_Game()
QMapIterator<int, Server_Player *> 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();
......
......@@ -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)
......
......@@ -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(); }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment