better null check (#3036)

This commit is contained in:
Zach H 2018-01-20 14:54:34 -05:00 committed by GitHub
parent 55029b6b68
commit 261d3ac591
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 11 deletions

View file

@ -31,12 +31,13 @@ void CardZone::retranslateUi()
void CardZone::clearContents()
{
for (int i = 0; i < cards.size(); i++) {
for (int i = 0; i < cards.size(); i++)
{
// 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.
const QList<CardItem *> &attachedCards = cards[i]->getAttachedCards();
for (int j = 0; j < attachedCards.size(); ++j)
attachedCards[j]->setParentItem(attachedCards[j]->getZone());
for (auto attachedCard : attachedCards)
attachedCard->setParentItem(attachedCard->getZone());
player->deleteCard(cards.at(i));
}