bugfix(aigroup): Prevent game crash when a player is selected in Replay playback (2)#2711
bugfix(aigroup): Prevent game crash when a player is selected in Replay playback (2)#2711Caball009 wants to merge 4 commits into
Conversation
29b2761 to
2909a9e
Compare
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Replaces the use-after-free getCount() == 0 heuristic with a safe doesGroupExist pointer-liveness check; updates the comment attribution and date |
| Generals/Code/GameEngine/Include/GameLogic/AI.h | Adds doesGroupExist(AIGroup* group) const declaration to the Generals AI class, resolving the missing-declaration issue from PR #1212's follow-up |
| Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp | Implements doesGroupExist using std::find over m_groupList; consistent with the existing destroyGroup pattern that already uses std::find on the same list |
| GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h | Mirrors the Generals header change, adding doesGroupExist declaration to the Zero Hour AI class |
| GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp | Mirrors the Generals implementation; identical doesGroupExist body using std::find over m_groupList |
Sequence Diagram
sequenceDiagram
participant GLD as GameLogicDispatch
participant AI as TheAI (AI singleton)
participant GL as m_groupList
GLD->>GLD: "currentlySelectedGroup != nullptr?"
alt pointer non-null
GLD->>AI: doesGroupExist(currentlySelectedGroup)
AI->>GL: std::find(begin, end, group)
GL-->>AI: iterator (found / end)
AI-->>GLD: true (exists) / false (destroyed)
alt group not in list (destroyed)
GLD->>GLD: return early — avoid use-after-free
else group still alive
GLD->>GLD: proceed to process selection
end
end
Reviews (3): Last reviewed commit: "Made 'AI::doesGroupExist' member functio..." | Re-trigger Greptile
xezon
left a comment
There was a problem hiding this comment.
Makes sense. I have not thought of that.
|
Replicated in Generals. |
With the fix from #1212
AIGroupPtr currentlySelectedGroupwould be accessed even if it had been destroyed and its memory deallocated. This is a use-after-free bug. It relies on the memory not being overwritten on deallocation.If macro
MEMORYPOOL_DEBUG(enabled byRTS_DEBUG) is enabled, freed memory is overwritten with a garbage value, so the game crashes whencurrentlySelectedGroupis dereferenced (at line 2132).TODO: