diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index a6e6959d..e21ec287 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -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 &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)); } diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index b7cf0e33..4a20d5b0 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -485,7 +485,9 @@ void Player::clear() QMapIterator i(zones); while (i.hasNext()) + { i.next().value()->clearContents(); + } clearCounters(); } @@ -1895,10 +1897,18 @@ void Player::addCard(CardItem *c) void Player::deleteCard(CardItem *c) { - if (dialogSemaphore) + if (c == nullptr) + { + return; + } + else if (dialogSemaphore) + { cardsToDelete.append(c); + } else + { c->deleteLater(); + } } void Player::addZone(CardZone *z) @@ -2062,8 +2072,13 @@ bool Player::clearCardsToDelete() if (cardsToDelete.isEmpty()) return false; - for (int i = 0; i < cardsToDelete.size(); ++i) - cardsToDelete[i]->deleteLater(); + for (auto &i : cardsToDelete) + { + if (i != nullptr) + { + i->deleteLater(); + } + } cardsToDelete.clear(); return true; @@ -2087,8 +2102,8 @@ void Player::actMoveCardXCardsFromTop() QList< const ::google::protobuf::Message * > commandList; ListOfCardsToMove idList; - for (int i = 0; i < cardList.size(); ++i) - idList.add_card()->set_card_id(cardList[i]->getId()); + for (auto &i : cardList) + idList.add_card()->set_card_id(i->getId()); if (cardList.isEmpty()) return; @@ -2552,7 +2567,7 @@ void Player::updateCardMenu(const CardItem *card) bool writeableCard = getLocal(); if (card->getZone() && card->getZone()->getIsView()) { - ZoneViewZone *view = static_cast(card->getZone()); + auto *view = dynamic_cast(card->getZone()); if (view->getRevealZone()) { if (view->getWriteableRevealZone()) diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 4ebd9441..6cb17568 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -434,12 +434,14 @@ void TabGame::emitUserEvent() { TabGame::~TabGame() { - if(replay) - delete replay; + delete replay; QMapIterator i(players); while (i.hasNext()) + { delete i.next().value(); + } + players.clear(); emit gameClosing(this);