better null check (#3036)
This commit is contained in:
parent
55029b6b68
commit
261d3ac591
3 changed files with 29 additions and 11 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -485,7 +485,9 @@ void Player::clear()
|
|||
|
||||
QMapIterator<QString, CardZone *> 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<ZoneViewZone *>(card->getZone());
|
||||
auto *view = dynamic_cast<ZoneViewZone *>(card->getZone());
|
||||
if (view->getRevealZone())
|
||||
{
|
||||
if (view->getWriteableRevealZone())
|
||||
|
|
|
@ -434,12 +434,14 @@ void TabGame::emitUserEvent() {
|
|||
|
||||
TabGame::~TabGame()
|
||||
{
|
||||
if(replay)
|
||||
delete replay;
|
||||
delete replay;
|
||||
|
||||
QMapIterator<int, Player *> i(players);
|
||||
while (i.hasNext())
|
||||
{
|
||||
delete i.next().value();
|
||||
}
|
||||
|
||||
players.clear();
|
||||
|
||||
emit gameClosing(this);
|
||||
|
|
Loading…
Reference in a new issue