diff --git a/common/server_game.cpp b/common/server_game.cpp index 97a76e8e..db756264 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -575,15 +575,19 @@ void Server_Game::unattachCards(GameEventStorage &ges, Server_Player *player) { QMutexLocker locker(&gameMutex); - QMapIterator zoneIterator(player->getZones()); - for (Server_CardZone *zone : player->getZones()) { - for (Server_Card *card : zone->getCards()) { + for (auto zone : player->getZones()) { + for (auto card : zone->getCards()) { if (card == nullptr) { continue; } + const auto &attachedCardsBase = card->getAttachedCards(); + if (attachedCardsBase.isEmpty()) { + continue; + } + // Make a copy of the list because the original one gets modified during the loop - QList attachedCards = card->getAttachedCards(); + QList attachedCards = {attachedCardsBase}; for (Server_Card *attachedCard : attachedCards) { attachedCard->getZone()->getPlayer()->unattachCard(ges, attachedCard); }