diff --git a/cockatrice/src/game_graphics/player/player_graphics_item.cpp b/cockatrice/src/game_graphics/player/player_graphics_item.cpp index 51b02ed0b..059527b7a 100644 --- a/cockatrice/src/game_graphics/player/player_graphics_item.cpp +++ b/cockatrice/src/game_graphics/player/player_graphics_item.cpp @@ -242,6 +242,9 @@ void PlayerGraphicsItem::onCounterRemoved(int counterId) if (playerMenu->getCountersMenu() && widget->getMenu()) { playerMenu->getCountersMenu()->removeAction(widget->getMenu()->menuAction()); } + if (commandZoneGraphicsItem && CounterNames::isTaxCounter(widget->getName())) { + commandZoneGraphicsItem->unregisterTaxCounter(widget); + } widget->delCounter(); rearrangeCounters(); } diff --git a/cockatrice/src/game_graphics/zones/command_zone.cpp b/cockatrice/src/game_graphics/zones/command_zone.cpp index 6b2b4139b..d26d1842a 100644 --- a/cockatrice/src/game_graphics/zones/command_zone.cpp +++ b/cockatrice/src/game_graphics/zones/command_zone.cpp @@ -160,6 +160,15 @@ void CommandZone::registerTaxCounter(AbstractCounter *counter) connect(counter, &QObject::destroyed, this, [this, counter]() { taxCounters.removeOne(counter); }); } +void CommandZone::unregisterTaxCounter(AbstractCounter *counter) +{ + if (!counter) { + return; + } + disconnect(counter, &QObject::destroyed, this, nullptr); + taxCounters.removeOne(counter); +} + void CommandZone::rearrangeTaxCounters() { int activeTaxCounterCount = 0; diff --git a/cockatrice/src/game_graphics/zones/command_zone.h b/cockatrice/src/game_graphics/zones/command_zone.h index 6e7d3a619..6706da466 100644 --- a/cockatrice/src/game_graphics/zones/command_zone.h +++ b/cockatrice/src/game_graphics/zones/command_zone.h @@ -89,6 +89,13 @@ public: void setMinimumHeight(int height); /** @brief Registers a tax counter widget for layout management. */ void registerTaxCounter(AbstractCounter *counter); + /** + * @brief Unregisters a tax counter widget from layout management. + * + * Call on removal: the widget outlives it via deleteLater(), so unregister synchronously + * to keep it out of the next layout pass. + */ + void unregisterTaxCounter(AbstractCounter *counter); /** @brief Lays out visible tax counters vertically in the top-left corner of the command zone. */ void rearrangeTaxCounters();