Unverified Commit ae743775 authored by ebbit1q's avatar ebbit1q Committed by GitHub
Browse files

do not edit the zone currently iterated on (#4345)

this can cause the iterator to become invalidated which will crash but
because of the data not always being moved it will often still work as
intended, giving the idea that it is random
parent 046a3649
......@@ -577,19 +577,17 @@ void Server_Game::unattachCards(GameEventStorage &ges, Server_Player *player)
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<Server_Card *> attachedCards = {attachedCardsBase};
QList<Server_Card *> attachedCards = card->getAttachedCards();
for (Server_Card *attachedCard : attachedCards) {
attachedCard->getZone()->getPlayer()->unattachCard(ges, attachedCard);
auto otherPlayer = attachedCard->getZone()->getPlayer();
// do not modify the current player's zone!
// this would cause the current card iterator to be invalidated!
// we only have to return cards owned by other players
// because the current player is leaving the game anyway
if (otherPlayer != player) {
otherPlayer->unattachCard(ges, attachedCard);
}
}
}
}
......
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