From d2bfef45962fde27ef58d42b7200bea3a3021a89 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Tue, 24 Mar 2026 05:38:40 +0000 Subject: [PATCH] fix(AI): Add null checks for training orders and factory lookup --- Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp | 6 ++++++ GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index b96483a33b5..0e96891500a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -1269,6 +1269,9 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad // ------------------------------------------------------------------------------------------------ Bool AIPlayer::startTraining( WorkOrder *order, Bool busyOK, AsciiString teamName) { + if( order->m_thing == nullptr ) + return FALSE; + Object *factory = findFactory(order->m_thing, busyOK); if( factory ) { @@ -1297,6 +1300,9 @@ Bool AIPlayer::startTraining( WorkOrder *order, Bool busyOK, AsciiString teamNam // ------------------------------------------------------------------------------------------------ Object *AIPlayer::findFactory(const ThingTemplate *thing, Bool busyOK) { + if( thing == nullptr ) + return nullptr; + Object *busyFactory = nullptr; // We prefer a factory that isn't busy. for( BuildListInfo *info = m_player->getBuildList(); info; info = info->getNext() ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index c59dfb9ae89..f673e6c3efe 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -1389,6 +1389,9 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad // ------------------------------------------------------------------------------------------------ Bool AIPlayer::startTraining( WorkOrder *order, Bool busyOK, AsciiString teamName) { + if( order->m_thing == nullptr ) + return FALSE; + Object *factory = findFactory(order->m_thing, busyOK); if( factory ) { @@ -1417,6 +1420,9 @@ Bool AIPlayer::startTraining( WorkOrder *order, Bool busyOK, AsciiString teamNam // ------------------------------------------------------------------------------------------------ Object *AIPlayer::findFactory(const ThingTemplate *thing, Bool busyOK) { + if( thing == nullptr ) + return nullptr; + Object *busyFactory = nullptr; // We prefer a factory that isn't busy. for( BuildListInfo *info = m_player->getBuildList(); info; info = info->getNext() ) {