Address weird crash case

This commit is contained in:
Zach Halpern 2024-12-03 20:34:56 -05:00
parent fa02cb885c
commit 39b5e3c758
3 changed files with 30 additions and 24 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() const
{ {
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

@ -222,7 +222,7 @@ private slots:
void actFlowT(); void actFlowT();
void actSetAnnotation(); void actSetAnnotation();
void actPlay(); void actPlay();
void actHide(); void actHide() const;
void actPlayFacedown(); void actPlayFacedown();
void actReveal(QAction *action); void actReveal(QAction *action);
void refreshShortcuts(); void refreshShortcuts();

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(???)";
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(???)";
return;
}
cards.removeOne(card); cards.removeOne(card);
reorganizeCards(); reorganizeCards();
emit cardCountChanged(); emit cardCountChanged();