[GEN][ZH] Prevent game crash when a player is selected in Replay playback #1212
+16
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change fixes a critical problem with AIGroup, that happens all the time in any match, but only crashes the Replay playback when a player is selected. The memory management of AIGroup is totally broken, and it will leak many AIGroups in AI matches (or matches that use AI scripts) and that will slow down iterating over
std::list<AIGroup *> m_groupList
.The Problem
AIGroup has a fundamental memory management flaw with its
AIGroup::remove
function. It deletes itself when all members are removed, which means that any non-AIGroup members holding a reference to that AIGroup will dangle when it is deleted.This happens all the time in
GameLogic::logicMessageDispatcher
with itscurrentlySelectedGroup
variable. It holds objects in a AIGroup, but that AIGroup can be deleted by external events, for exampleThere are multiple code paths like this that can delete
currentlySelectedGroup
.The Solution
With RETAIL_COMPATIBLE_CRC,
GameLogic::logicMessageDispatcher
now uses a massive hack to avoid crashing. It uses this hack because fixing AIGroup properly will mismatch with Retail. GenTool applies this exact hack since more than a decade.TODO
Test against more replays