From e645451f44b99ef8543bc030c5665c9689a4179e Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:23:25 +0100 Subject: [PATCH 1/2] bugfix(AIPlayer): Fix crash when AI player attempts to build supply center with invalid name --- .../Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 74ed1cf47eb..557c3914db0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -1859,8 +1859,15 @@ void AIPlayer::buildUpgrade(const AsciiString &upgrade) // ------------------------------------------------------------------------------------------------ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName) { - Object *bestSupplyWarehouse = findSupplyCenter(minimumCash); const ThingTemplate* tTemplate = TheThingFactory->findTemplate(thingName); + if (!tTemplate) + { + DEBUG_CRASH(("Template %s should exist; check ini and script files.", thingName.str())); + return; + } + + Object *bestSupplyWarehouse = findSupplyCenter(minimumCash); + if (!tTemplate->isKindOf(KINDOF_CASH_GENERATOR)) { // Build by the current warehouse. Object *curWarehouse = TheGameLogic->findObjectByID(m_curWarehouseID); @@ -1870,7 +1877,7 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName) } - if (bestSupplyWarehouse && tTemplate) { + if (bestSupplyWarehouse) { Coord3D location; location = *bestSupplyWarehouse->getPosition(); // offset back towards the base. From 8c958f6b296b7401301a01d3b9e35e7af0d9f2d0 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sun, 18 Jan 2026 16:57:45 +0100 Subject: [PATCH 2/2] Replicated in Generals. --- .../Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 9bd88bcb319..06803e930df 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -1735,8 +1735,15 @@ void AIPlayer::buildUpgrade(const AsciiString &upgrade) // ------------------------------------------------------------------------------------------------ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName) { - Object *bestSupplyWarehouse = findSupplyCenter(minimumCash); const ThingTemplate* tTemplate = TheThingFactory->findTemplate(thingName); + if (!tTemplate) + { + DEBUG_CRASH(("Template %s should exist; check ini and script files.", thingName.str())); + return; + } + + Object *bestSupplyWarehouse = findSupplyCenter(minimumCash); + if (!tTemplate->isKindOf(KINDOF_CASH_GENERATOR)) { // Build by the current warehouse. Object *curWarehouse = TheGameLogic->findObjectByID(m_curWarehouseID); @@ -1746,7 +1753,7 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName) } - if (bestSupplyWarehouse && tTemplate) { + if (bestSupplyWarehouse) { Coord3D location; location = *bestSupplyWarehouse->getPosition(); // offset back towards the base.