unify(pathfinder): Remove legacy debug and merge safe code#2381
unify(pathfinder): Remove legacy debug and merge safe code#2381Mauller wants to merge 5 commits intoTheSuperHackers:mainfrom
Conversation
c684e58 to
3ed0058
Compare
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h | CellType enum unified with GeneralsMD (adds CELL_BRIDGE_IMPASSABLE=0x05, renumbers CELL_IMPASSABLE to 0x06, removes CELL_unused); setTypeAsObstacle/removeObstacle return Bool; setCostSoFar/setTotalCost add m_info null guards; getParentCell gains m_info null safety via ternary chain; typo fixes. |
| Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | Adds IS_IMPASSABLE helper (no Generals call sites yet, temporary during unification), changes setTypeAsObstacle/removeObstacle to return Bool, replaces costToHierGoal assert with graceful null-return, adds CELL_BRIDGE_IMPASSABLE handling in switch/debug rendering, removes several debug assertions and QPF timing blocks. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h | Removes unused Bool insert parameter from markZonesDirty() declaration — straightforward signature cleanup. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | Updates markZonesDirty() implementation to remove the now-unused insert parameter, and updates all four call sites accordingly — mechanical, safe change. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PathfindCell::CellType] --> B[CELL_CLEAR = 0x00]
A --> C[CELL_WATER = 0x01]
A --> D[CELL_CLIFF = 0x02]
A --> E[CELL_RUBBLE = 0x03]
A --> F[CELL_OBSTACLE = 0x04\nOccupied by a structure]
A --> G[CELL_BRIDGE_IMPASSABLE = 0x05\nNew in Generals via this PR]
A --> H[CELL_IMPASSABLE = 0x06\nRenum from 0x0B]
F --> IS[IS_IMPASSABLE helper\nreturns true]
G --> IS
H --> IS
IS --> LOCO[chooseBestLocomotorForPosition\nreturns LOCOMOTORSURFACE_AIR]
G -.->|No setter yet in Generals| NOTE[CELL_BRIDGE_IMPASSABLE\nnever set on cells in Generals\nfuture unification work]
G --> DBG[doDebugIcons\nblue+red color]
Last reviewed commit: 95cfca3
Additional Comments (1)
The following guard was removed without any replacement: if (m_maxZone >= m_zonesAllocated) {
RELEASE_CRASH("Pathfind allocation error - fatal. see jba.");
}Unlike the Could you confirm that Prompt To Fix With AIThis is a comment left during a code review.
Path: Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Line: 2736-2740
Comment:
**Removed `RELEASE_CRASH` guard exposes out-of-bounds access**
The following guard was removed without any replacement:
```cpp
if (m_maxZone >= m_zonesAllocated) {
RELEASE_CRASH("Pathfind allocation error - fatal. see jba.");
}
```
Unlike the `DEBUG_*` macros removed elsewhere in this PR, `RELEASE_CRASH` fires in **all** build configurations, not only debug builds. The guard immediately precedes the loops that index into `m_hierarchicalZones`, `m_groundCliffZones`, `m_groundWaterZones`, `m_groundRubbleZones`, `m_terrainZones`, and `m_crusherZones` up to `m_maxZone`. All of these arrays are sized to `m_zonesAllocated` by `allocateZones()`. If `m_maxZone >= m_zonesAllocated` were ever true, the subsequent flattening loops would perform out-of-bounds array accesses, causing undefined behaviour or memory corruption.
Could you confirm that `allocateZones()` (called just before) always guarantees `m_zonesAllocated > m_maxZone`, making this guard provably unreachable? If so, a `DEBUG_ASSERTCRASH` at minimum would be preferable to a silent removal.
How can I resolve this? If you propose a fix, please make it concise. |
3ed0058 to
563ca66
Compare
|
Mistakenly removed a difference that had a logical change, corrected that and reverted that part of the debug code removal as it also had a continue statement within it. |
| DEBUG_ASSERTCRASH(m_info, ("Has to have info.")); | ||
| if( !m_info ) | ||
| { | ||
| DEBUG_CRASH( ("Has to have info.") ); |
There was a problem hiding this comment.
wondering if the debug_crash is still needed with the patch hack.
There was a problem hiding this comment.
I honestly wouldn't be surprised if they were seeing pathfinding crashes due to all the problems we already cleaned up.
Can't wait to get rid of or at least conditionally remove code like this when i get the non allocating pathfinding going.
xezon
left a comment
There was a problem hiding this comment.
Very clean commits. Looks very safe.
The commit titles can be improved.
All/most merge commits that I made are titled in the following style:
unify(system): Merge ClassName, FileName code from GameName
563ca66 to
585a757
Compare
|
Updated commit titles |
|
Can you also polish the other titles a bit? The first one writes generals game title with lowercase letter. Better: |
…ndCell::removeObstacle() from Zero Hour (#2381)
…om Zero Hour (#2381)
…arkZonesDirty() (#2381)
585a757 to
95cfca3
Compare
Tweaked that and the PathfindCell commit |
merge by rebase
This PR is a small breakout from the main unify PR to cleanup legacy debug code from generals and to merge blocks of safe to merge code.
This mostly focuses on code that has no possible functional changes that require conditional compilation.
Only PathfindCell::costToHier() has a functional change which actually prevents a crash, so would not mismatch if the altered code was ever hit.
The merging of the
CellTypeenumeration is completely safe as the pathfind cell types are only ever used internally within the pathfinder so they can take whatever value we please. Only instances where their use has altered between generals and zero hour will cause a mismatch.The only time external data is used to set PathfindCell types is within
classifyMapwhen calls toTheTerrainLogic->isCliffCellorTheTerrainLogic->isUnderwaterare called and setCELL_CLIFForCELL_WATERfromCellType.The removal of the argument for markZonesDirty in zero hours code is a small thing to move the unification along more before hitting the more dangerous stuff within PathfindZoneManger.