-
Notifications
You must be signed in to change notification settings - Fork 117
[GEN][ZH] Fix AIGroup memory management and leaks #1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Mauller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Horrible hacks but similar to what i had to do with the pathfinding.
|
@helmutbuhler Can you test this against a few replays please? |
I checked with about 500 replays. No mismatches. |
Nice. Thank you. |
be5868c to
48302f4
Compare
|
Replicated in Generals with conflicts. |
|
Compilation tested with RETAIL_COMPATIBLE_CRC 0 for both titles. Runtime tested in Zero Hour. |
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::removefunction. 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::logicMessageDispatcherwith itscurrentlySelectedGroupvariable. 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
Properly reference count AIGroup so that an AIGroup is only destroyed when all owners let go off it. This fixes all problems, any potential leaks, crashes. It also makes the code simpler in some places.
The reference counted AIGroup is compiled out with RETAIL_COMPATIBLE_AIGROUP, because it WILL mismatch with Retail, because of all the memory leaks and whatever else happens when touching this code. However, !RETAIL_COMPATIBLE_AIGROUP is compatible with the Golden Replay 1, likely because the humans do not use all the scripts that leak AIGroups.
TODO