mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 03:23:56 -07:00
[Game] Fix CardZoneLogic::clearContents() (#6356)
Took 6 minutes Took 28 seconds Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
1931eb11a9
commit
553952132f
1 changed files with 13 additions and 6 deletions
|
|
@ -148,17 +148,24 @@ void CardZoneLogic::moveAllToZone()
|
||||||
|
|
||||||
void CardZoneLogic::clearContents()
|
void CardZoneLogic::clearContents()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cards.size(); i++) {
|
// First gather the cards into a safe temporary list.
|
||||||
|
const CardList toClear = cards;
|
||||||
|
|
||||||
|
// Detach and notify attached cards and zones *before* deleting anything.
|
||||||
|
for (CardItem *card : toClear) {
|
||||||
// If an incorrectly implemented server doesn't return attached cards to whom they belong before dropping a
|
// If an incorrectly implemented server doesn't return attached cards to whom they belong before dropping a
|
||||||
// player, we have to return them to avoid a crash.
|
// player, we have to return them to avoid a crash.
|
||||||
|
const QList<CardItem *> &attachedCards = card->getAttachedCards();
|
||||||
const QList<CardItem *> &attachedCards = cards[i]->getAttachedCards();
|
for (CardItem *attachedCard : attachedCards) {
|
||||||
for (auto attachedCard : attachedCards) {
|
|
||||||
emit attachedCard->getZone()->cardAdded(attachedCard);
|
emit attachedCard->getZone()->cardAdded(attachedCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
player->deleteCard(cards.at(i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now request deletions after all manipulations are done.
|
||||||
|
for (CardItem *card : toClear) {
|
||||||
|
player->deleteCard(card);
|
||||||
|
}
|
||||||
|
|
||||||
cards.clear();
|
cards.clear();
|
||||||
emit cardCountChanged();
|
emit cardCountChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue