Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(ai): guard the tunnel guard against a missing attack state

Olcay Seygan92707eeadcfc
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
index dd960a6c0..073a91573 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
@@ -495,6 +495,15 @@ StateReturnType AITNGuardOuterState::onEnter( void )
//--------------------------------------------------------------------------------------
StateReturnType AITNGuardOuterState::update( void )
{
+ /* onEnter has two ways out that never build the attack state - patrol mode, and a nemesis that
+ has stopped existing between being picked and being chased - and onExit leaves it NULL as
+ well. AIGuardOuterState::update, which is the same function for units that are not in a
+ tunnel network, has carried this line since EA wrote it; this copy did not, and the tunnel
+ version therefore reads through a null pointer and takes the whole game with it. Caught by
+ a headless batch: "Uncaught Exception in GameEngine::update", access address 0x20. */
+ if (m_attackState == NULL)
+ return STATE_SUCCESS;
+
Object *owner = getMachineOwner();
Object* goalObj = m_attackState->getMachineGoalObject();
if (goalObj)