Address weird crash case (#5221)

* Address weird crash case

* Address weird crash case

* remove const
This commit is contained in:
Zach H 2024-12-05 03:18:41 -08:00 committed by GitHub
parent fa02cb885c
commit e4cfe08113
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 22 deletions

View file

@ -130,8 +130,13 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->ignore();
}
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
void CardZone::addCard(CardItem *card, const bool reorganize, const int x, const int y)
{
if (!card) {
qDebug() << "CardZone::addCard() card is null, this shouldn't normally happen";
return;
}
for (auto *view : views) {
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
view->addCard(new CardItem(player, nullptr, card->getName(), card->getProviderId(), card->getId()),
@ -153,7 +158,7 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName)
CardItem *c = cards.findCard(cardId);
if (!c) {
qDebug() << "CardZone::getCard: card id=" << cardId << "not found";
return 0;
return nullptr;
}
// If the card's id is -1, this zone is invisible,
// so we need to give the card an id and a name as it comes out.
@ -179,7 +184,7 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
position = 0;
}
if (position >= cards.size())
return 0;
return nullptr;
CardItem *c = cards.takeAt(position);
@ -196,6 +201,11 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
void CardZone::removeCard(CardItem *card)
{
if (!card) {
qDebug() << "CardZone::removeCard: card is null, this shouldn't normally happen";
return;
}
cards.removeOne(card);
reorganizeCards();
emit cardCountChanged();