Skip to content

Commit 2909a9e

Browse files
committed
bugfix(aigroup): Prevent game crash when a player is selected in Replay playback.
1 parent 05e518d commit 2909a9e

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,10 +2120,9 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
21202120
}
21212121

21222122
#if RETAIL_COMPATIBLE_AIGROUP
2123-
// TheSuperHackers @bugfix xezon 28/06/2025 This hack avoids crashing when players are selected during Replay playback.
2124-
// It can read data from an already deleted AIGroup and return this function when its member size is 0, signifying that
2125-
// it is indeed deleted.
2126-
if (currentlySelectedGroup && currentlySelectedGroup->getCount() == 0)
2123+
// TheSuperHackers @bugfix xezon/Caball009 14/05/2026 This hack avoids crashing when players are selected during Replay playback.
2124+
// The current AI group may have been destroyed, and its memory deallocated, in which case it shouldn't be used.
2125+
if (currentlySelectedGroup && !TheAI->doesGroupExist(currentlySelectedGroup))
21272126
return;
21282127
#endif
21292128

GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class AI : public SubsystemInterface, public Snapshot
279279
AIGroupPtr createGroup(); ///< instantiate a new AI Group
280280
void destroyGroup( AIGroup *group ); ///< destroy the given AI Group
281281
AIGroup *findGroup( UnsignedInt id ); ///< return the AI Group with the given ID
282+
Bool doesGroupExist(AIGroup* group); ///< return whether the given AI Group exists, i.e. is part of the group list
282283

283284
// Formation info
284285
enum FormationID getNextFormationID();

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ AIGroup *AI::findGroup( UnsignedInt id )
497497
return nullptr;
498498
}
499499

500+
Bool AI::doesGroupExist(AIGroup* group)
501+
{
502+
return std::find(m_groupList.begin(), m_groupList.end(), group) != m_groupList.end();
503+
}
504+
500505
//--------------------------------------------------------------------------------------------------------
501506
/**
502507
* Get the next formation id.

0 commit comments

Comments
 (0)