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

@ -1693,7 +1693,7 @@ void Player::actCreatePredefinedToken()
void Player::actCreateRelatedCard() void Player::actCreateRelatedCard()
{ {
CardItem *sourceCard = game->getActiveCard(); const CardItem *sourceCard = game->getActiveCard();
if (!sourceCard) { if (!sourceCard) {
return; return;
} }
@ -1714,7 +1714,7 @@ void Player::actCreateRelatedCard()
void Player::actCreateAllRelatedCards() void Player::actCreateAllRelatedCards()
{ {
CardItem *sourceCard = game->getActiveCard(); const CardItem *sourceCard = game->getActiveCard();
if (!sourceCard) { if (!sourceCard) {
return; return;
} }
@ -3247,11 +3247,10 @@ void Player::actSetPT()
void Player::actDrawArrow() void Player::actDrawArrow()
{ {
if (!game->getActiveCard()) { auto *card = game->getActiveCard();
return; if (card) {
card->drawArrow(Qt::red);
} }
game->getActiveCard()->drawArrow(Qt::red);
} }
void Player::actIncP() void Player::actIncP()
@ -3436,30 +3435,27 @@ void Player::actCardCounterTrigger()
void Player::actPlay() void Player::actPlay()
{ {
if (!game->getActiveCard()) { auto *card = game->getActiveCard();
return; if (card) {
const bool cipt = card->getInfo() ? card->getInfo()->getCipt() : false;
playCard(card, false, cipt);
} }
bool cipt = game->getActiveCard()->getInfo() ? game->getActiveCard()->getInfo()->getCipt() : false;
playCard(game->getActiveCard(), false, cipt);
} }
void Player::actHide() void Player::actHide()
{ {
if (!game->getActiveCard()) { auto *card = game->getActiveCard();
return; if (card) {
card->getZone()->removeCard(card);
} }
game->getActiveCard()->getZone()->removeCard(game->getActiveCard());
} }
void Player::actPlayFacedown() void Player::actPlayFacedown()
{ {
if (!game->getActiveCard()) { auto *card = game->getActiveCard();
return; if (card) {
playCard(card, true, false);
} }
playCard(game->getActiveCard(), true, false);
} }
void Player::actReveal(QAction *action) void Player::actReveal(QAction *action)

View file

@ -130,8 +130,13 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->ignore(); 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) { for (auto *view : views) {
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) { if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
view->addCard(new CardItem(player, nullptr, card->getName(), card->getProviderId(), card->getId()), 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); CardItem *c = cards.findCard(cardId);
if (!c) { if (!c) {
qDebug() << "CardZone::getCard: card id=" << cardId << "not found"; qDebug() << "CardZone::getCard: card id=" << cardId << "not found";
return 0; return nullptr;
} }
// If the card's id is -1, this zone is invisible, // 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. // 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; position = 0;
} }
if (position >= cards.size()) if (position >= cards.size())
return 0; return nullptr;
CardItem *c = cards.takeAt(position); CardItem *c = cards.takeAt(position);
@ -196,6 +201,11 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
void CardZone::removeCard(CardItem *card) void CardZone::removeCard(CardItem *card)
{ {
if (!card) {
qDebug() << "CardZone::removeCard: card is null, this shouldn't normally happen";
return;
}
cards.removeOne(card); cards.removeOne(card);
reorganizeCards(); reorganizeCards();
emit cardCountChanged(); emit cardCountChanged();