From 9c3be1b85169d255881169c89b31260704c9f7ed Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:06:20 +0200 Subject: [PATCH] check for null zone during card item teardown (#6149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * check for null zone during card item teardown Took 1 hour 32 minutes Took 24 seconds * Also check for it in the successful branch. Took 6 minutes * Comment. Took 5 minutes --------- Co-authored-by: Lukas BrĂ¼bach --- cockatrice/src/game/board/card_item.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/game/board/card_item.cpp b/cockatrice/src/game/board/card_item.cpp index afcd38789..e3b985f11 100644 --- a/cockatrice/src/game/board/card_item.cpp +++ b/cockatrice/src/game/board/card_item.cpp @@ -185,13 +185,25 @@ void CardItem::setAttachedTo(CardItem *_attachedTo) gridPoint.setX(-1); attachedTo = _attachedTo; if (attachedTo != nullptr) { - emit attachedTo->zone->cardAdded(this); - attachedTo->addAttachedCard(this); - if (zone != attachedTo->getZone()) { - attachedTo->getZone()->reorganizeCards(); + // If the zone is being torn down, it might already be null by the time a card tries to un-attach all its + // attached cards + if (attachedTo->zone == nullptr) { + deleteLater(); + } else { + emit attachedTo->zone->cardAdded(this); + attachedTo->addAttachedCard(this); + if (zone != attachedTo->getZone()) { + attachedTo->getZone()->reorganizeCards(); + } } } else { - emit zone->cardAdded(this); + // If the zone is being torn down, it might already be null by the time a card tries to un-attach all its + // attached cards + if (zone == nullptr) { + deleteLater(); + } else { + emit zone->cardAdded(this); + } } if (zone != nullptr) {