From be5c989214df73f2e972568b3a7ad9940b1b9374 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Mon, 15 Jun 2026 11:21:46 -0400 Subject: [PATCH] Resolve PlayerActions at call time instead of capturing at construction --- .../player/menu/command_zone_menu.cpp | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/cockatrice/src/game_graphics/player/menu/command_zone_menu.cpp b/cockatrice/src/game_graphics/player/menu/command_zone_menu.cpp index 2b163b31a..513b036f5 100644 --- a/cockatrice/src/game_graphics/player/menu/command_zone_menu.cpp +++ b/cockatrice/src/game_graphics/player/menu/command_zone_menu.cpp @@ -31,40 +31,56 @@ CommandZoneMenu::CommandZoneMenu(PlayerGraphicsItem *_player, QMenu *playerMenu) addAction(aViewZone); addSeparator(); - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); - aIncreaseCommanderTax = new QAction(this); - connect(aIncreaseCommanderTax, &QAction::triggered, this, - [playerActions]() { playerActions->actModifyTaxCounter(CounterIds::CommanderTax, 1); }); + connect(aIncreaseCommanderTax, &QAction::triggered, this, [this]() { + if (auto *logic = player->getLogic()) { + logic->getPlayerActions()->actModifyTaxCounter(CounterIds::CommanderTax, 1); + } + }); addAction(aIncreaseCommanderTax); aDecreaseCommanderTax = new QAction(this); - connect(aDecreaseCommanderTax, &QAction::triggered, this, - [playerActions]() { playerActions->actModifyTaxCounter(CounterIds::CommanderTax, -1); }); + connect(aDecreaseCommanderTax, &QAction::triggered, this, [this]() { + if (auto *logic = player->getLogic()) { + logic->getPlayerActions()->actModifyTaxCounter(CounterIds::CommanderTax, -1); + } + }); addAction(aDecreaseCommanderTax); addSeparator(); aIncreasePartnerTax = new QAction(this); - connect(aIncreasePartnerTax, &QAction::triggered, this, - [playerActions]() { playerActions->actModifyTaxCounter(CounterIds::PartnerTax, 1); }); + connect(aIncreasePartnerTax, &QAction::triggered, this, [this]() { + if (auto *logic = player->getLogic()) { + logic->getPlayerActions()->actModifyTaxCounter(CounterIds::PartnerTax, 1); + } + }); addAction(aIncreasePartnerTax); aDecreasePartnerTax = new QAction(this); - connect(aDecreasePartnerTax, &QAction::triggered, this, - [playerActions]() { playerActions->actModifyTaxCounter(CounterIds::PartnerTax, -1); }); + connect(aDecreasePartnerTax, &QAction::triggered, this, [this]() { + if (auto *logic = player->getLogic()) { + logic->getPlayerActions()->actModifyTaxCounter(CounterIds::PartnerTax, -1); + } + }); addAction(aDecreasePartnerTax); addSeparator(); aToggleCommanderTaxCounter = new QAction(this); - connect(aToggleCommanderTaxCounter, &QAction::triggered, this, - [playerActions]() { playerActions->actToggleTaxCounter(CounterIds::CommanderTax); }); + connect(aToggleCommanderTaxCounter, &QAction::triggered, this, [this]() { + if (auto *logic = player->getLogic()) { + logic->getPlayerActions()->actToggleTaxCounter(CounterIds::CommanderTax); + } + }); addAction(aToggleCommanderTaxCounter); aTogglePartnerTaxCounter = new QAction(this); - connect(aTogglePartnerTaxCounter, &QAction::triggered, this, - [playerActions]() { playerActions->actToggleTaxCounter(CounterIds::PartnerTax); }); + connect(aTogglePartnerTaxCounter, &QAction::triggered, this, [this]() { + if (auto *logic = player->getLogic()) { + logic->getPlayerActions()->actToggleTaxCounter(CounterIds::PartnerTax); + } + }); addAction(aTogglePartnerTaxCounter); addSeparator();