Fix racetime condition with token cloning (#4156)

* Fix #2820 by removing (this->setCursor) as this was null by the time we hit this component due to a racetime condition.

* check if card player pointer is valid before setting cursor

Co-authored-by: ebbit1q <ebbit1q@gmail.com>
This commit is contained in:
Zach H 2020-11-22 20:25:23 -05:00 committed by GitHub
parent 0d842b5a35
commit 6e00db4ef6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,22 +48,22 @@ CardItem::~CardItem()
void CardItem::prepareDelete() void CardItem::prepareDelete()
{ {
if (owner) { if (owner != nullptr) {
if (owner->getCardMenu() == cardMenu) { if (owner->getCardMenu() == cardMenu) {
owner->setCardMenu(0); owner->setCardMenu(nullptr);
owner->getGame()->setActiveCard(0); owner->getGame()->setActiveCard(nullptr);
} }
owner = 0; owner = nullptr;
} }
while (!attachedCards.isEmpty()) { while (!attachedCards.isEmpty()) {
attachedCards.first()->setZone(0); // so that it won't try to call reorganizeCards() attachedCards.first()->setZone(nullptr); // so that it won't try to call reorganizeCards()
attachedCards.first()->setAttachedTo(0); attachedCards.first()->setAttachedTo(nullptr);
} }
if (attachedTo) { if (attachedTo != nullptr) {
attachedTo->removeAttachedCard(this); attachedTo->removeAttachedCard(this);
attachedTo = 0; attachedTo = nullptr;
} }
} }
@ -265,9 +265,10 @@ CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPoin
void CardItem::deleteDragItem() void CardItem::deleteDragItem()
{ {
if (dragItem) if (dragItem) {
dragItem->deleteLater(); dragItem->deleteLater();
dragItem = NULL; }
dragItem = nullptr;
} }
void CardItem::drawArrow(const QColor &arrowColor) void CardItem::drawArrow(const QColor &arrowColor)
@ -362,7 +363,7 @@ void CardItem::playCard(bool faceDown)
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::RightButton) { if (event->button() == Qt::RightButton) {
if (cardMenu && !cardMenu->isEmpty() && owner) { if (cardMenu && !cardMenu->isEmpty() && owner != nullptr) {
owner->updateCardMenu(this); owner->updateCardMenu(this);
cardMenu->exec(event->screenPos()); cardMenu->exec(event->screenPos());
} }
@ -370,7 +371,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
(!SettingsCache::instance().getDoubleClickToPlay())) { (!SettingsCache::instance().getDoubleClickToPlay())) {
bool hideCard = false; bool hideCard = false;
if (zone && zone->getIsView()) { if (zone && zone->getIsView()) {
ZoneViewZone *view = static_cast<ZoneViewZone *>(zone); auto *view = static_cast<ZoneViewZone *>(zone);
if (view->getRevealZone() && !view->getWriteableRevealZone()) if (view->getRevealZone() && !view->getWriteableRevealZone())
hideCard = true; hideCard = true;
} }
@ -381,7 +382,9 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
} }
} }
setCursor(Qt::OpenHandCursor); if (owner != nullptr){ // cards without owner will be deleted
setCursor(Qt::OpenHandCursor);
}
AbstractCardItem::mouseReleaseEvent(event); AbstractCardItem::mouseReleaseEvent(event);
} }