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()
|
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,
|
// 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.
|
// we have to return them to avoid a crash.
|
||||||
const QList<CardItem *> &attachedCards = cards[i]->getAttachedCards();
|
const QList<CardItem *> &attachedCards = cards[i]->getAttachedCards();
|
||||||
for (int j = 0; j < attachedCards.size(); ++j)
|
for (auto attachedCard : attachedCards)
|
||||||
attachedCards[j]->setParentItem(attachedCards[j]->getZone());
|
attachedCard->setParentItem(attachedCard->getZone());
|
||||||
|
|
||||||
player->deleteCard(cards.at(i));
|
player->deleteCard(cards.at(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,7 +485,9 @@ void Player::clear()
|
||||||
|
|
||||||
QMapIterator<QString, CardZone *> i(zones);
|
QMapIterator<QString, CardZone *> i(zones);
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
|
{
|
||||||
i.next().value()->clearContents();
|
i.next().value()->clearContents();
|
||||||
|
}
|
||||||
|
|
||||||
clearCounters();
|
clearCounters();
|
||||||
}
|
}
|
||||||
|
@ -1895,10 +1897,18 @@ void Player::addCard(CardItem *c)
|
||||||
|
|
||||||
void Player::deleteCard(CardItem *c)
|
void Player::deleteCard(CardItem *c)
|
||||||
{
|
{
|
||||||
if (dialogSemaphore)
|
if (c == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (dialogSemaphore)
|
||||||
|
{
|
||||||
cardsToDelete.append(c);
|
cardsToDelete.append(c);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
c->deleteLater();
|
c->deleteLater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::addZone(CardZone *z)
|
void Player::addZone(CardZone *z)
|
||||||
|
@ -2062,8 +2072,13 @@ bool Player::clearCardsToDelete()
|
||||||
if (cardsToDelete.isEmpty())
|
if (cardsToDelete.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < cardsToDelete.size(); ++i)
|
for (auto &i : cardsToDelete)
|
||||||
cardsToDelete[i]->deleteLater();
|
{
|
||||||
|
if (i != nullptr)
|
||||||
|
{
|
||||||
|
i->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
cardsToDelete.clear();
|
cardsToDelete.clear();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -2087,8 +2102,8 @@ void Player::actMoveCardXCardsFromTop()
|
||||||
|
|
||||||
QList< const ::google::protobuf::Message * > commandList;
|
QList< const ::google::protobuf::Message * > commandList;
|
||||||
ListOfCardsToMove idList;
|
ListOfCardsToMove idList;
|
||||||
for (int i = 0; i < cardList.size(); ++i)
|
for (auto &i : cardList)
|
||||||
idList.add_card()->set_card_id(cardList[i]->getId());
|
idList.add_card()->set_card_id(i->getId());
|
||||||
|
|
||||||
if (cardList.isEmpty())
|
if (cardList.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -2552,7 +2567,7 @@ void Player::updateCardMenu(const CardItem *card)
|
||||||
bool writeableCard = getLocal();
|
bool writeableCard = getLocal();
|
||||||
if (card->getZone() && card->getZone()->getIsView())
|
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->getRevealZone())
|
||||||
{
|
{
|
||||||
if (view->getWriteableRevealZone())
|
if (view->getWriteableRevealZone())
|
||||||
|
|
|
@ -434,12 +434,14 @@ void TabGame::emitUserEvent() {
|
||||||
|
|
||||||
TabGame::~TabGame()
|
TabGame::~TabGame()
|
||||||
{
|
{
|
||||||
if(replay)
|
delete replay;
|
||||||
delete replay;
|
|
||||||
|
|
||||||
QMapIterator<int, Player *> i(players);
|
QMapIterator<int, Player *> i(players);
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
|
{
|
||||||
delete i.next().value();
|
delete i.next().value();
|
||||||
|
}
|
||||||
|
|
||||||
players.clear();
|
players.clear();
|
||||||
|
|
||||||
emit gameClosing(this);
|
emit gameClosing(this);
|
||||||
|
|
Loading…
Reference in a new issue