From 52d46c56d219104476c2259811122ef0f762cd70 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sun, 15 Feb 2026 19:05:51 +0100 Subject: [PATCH] bugfix(pathfinder): Fix uninitialized variable in Pathfinder::tightenPathCallback to prevent mismatches. --- .../Code/GameEngine/Include/GameLogic/AIPathfind.h | 2 +- .../GameEngine/Source/GameLogic/AI/AIPathfind.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h index a7ab136c909..15bad46cd59 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h @@ -767,7 +767,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot Bool checkForPossible(Bool isCrusher, Int fromZone, Bool center, const LocomotorSet& locomotorSet, Int cellX, Int cellY, PathfindLayerEnum layer, Coord3D *dest, Bool startingInObstacle) ; void getRadiusAndCenter(const Object *obj, Int &iRadius, Bool ¢er); - void adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coord3D &pos, PathfindLayerEnum layer); + static void adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coord3D &pos, PathfindLayerEnum layer); Bool checkDestination(const Object *obj, Int cellX, Int cellY, PathfindLayerEnum layer, Int iRadius, Bool centerInCell); Bool checkForMovement(const Object *obj, TCheckMovementInfo &info); Bool segmentIntersectsTallBuilding(const PathNode *curNode, PathNode *nextNode, diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index f6f4c98fc5d..baab26ab261 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -8367,7 +8367,18 @@ struct TightenPathStruct if (d->layer != to->getLayer()) { return 0; // abort. } + + // TheSuperHackers @todo Caball009 15/02/2026 This is an incomplete workaround to initialize the variable, + // and needs to be replaced with a proper opt-in mechanism. The fix may introduce too many new mismatches to enable unconditionally, + // and the uninitialized values vary too much to imitate. Coord3D pos; +#if RETAIL_COMPATIBLE_PATHFINDING + if (s_useFixedPathfinding) +#endif + { + adjustCoordToCell(to_x, to_y, d->center, pos, to->getLayer()); + } + if (!TheAI->pathfinder()->checkForAdjust(d->obj, *d->locomotorSet, true, to_x, to_y, to->getLayer(), d->radius, d->center, &pos, nullptr)) { return 0; // bail early @@ -8977,7 +8988,7 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet } -void Pathfinder::adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coord3D &pos, PathfindLayerEnum layer) +/*static*/ void Pathfinder::adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coord3D& pos, PathfindLayerEnum layer) { if (centerInCell) { pos.x = ((Real)cellX + 0.5f) * PATHFIND_CELL_SIZE_F;