From 3a6bb687838c36eacb5078988dfdc2c5f1ad7ba4 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Thu, 26 Mar 2026 21:23:21 +0000 Subject: [PATCH] bugfix(AI): Re-validate target before firing to prevent attacking dead units --- Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp | 4 ++++ GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index e9406426a1..69608c4750 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -5096,6 +5096,10 @@ StateReturnType AIAttackFireWeaponState::update() if (m_att->isAttackingObject()) { + // Re-validate victim immediately before firing; it may have been destroyed since the earlier check. + if (!victim || victim->isEffectivelyDead()) + return STATE_FAILURE; + obj->fireCurrentWeapon(victim); // clear this, just in case. obj->clearStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_IGNORING_STEALTH ) ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 6a0ccd6226..92ceeca545 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -5256,6 +5256,9 @@ StateReturnType AIAttackFireWeaponState::update() // If the concept of linked turrets is further developed then God help you, and put more code right here // that lookl like the //LINKED TURRETS// block, below + // Re-validate victim immediately before firing; it may have been destroyed since the earlier check. + if (!victim || victim->isEffectivelyDead()) + return STATE_FAILURE; obj->fireCurrentWeapon(victim);