Skip to content

Commit 5871a88

Browse files
authored
bugfix(pathfinder): Improve initialization of uninitialized variable in Pathfinder::classifyFence (TheSuperHackers#2460)
1 parent da74846 commit 5871a88

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

Core/GameEngine/Include/GameLogic/AIPathfind.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,11 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
917917
Int m_queuePRHead;
918918
Int m_queuePRTail;
919919
Int m_cumulativeCellsAllocated;
920+
921+
#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
922+
public:
923+
Bool m_classifyFenceZeroInit;
924+
#endif
920925
};
921926

922927

Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,6 +4104,10 @@ void Pathfinder::reset()
41044104
s_useFixedPathfinding = false;
41054105
s_forceCleanCells = false;
41064106
#endif
4107+
4108+
#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
4109+
m_classifyFenceZeroInit = false;
4110+
#endif
41074111
}
41084112

41094113
/**
@@ -4243,10 +4247,18 @@ void Pathfinder::classifyFence( Object *obj, Bool insert )
42434247
#if RETAIL_COMPATIBLE_CRC
42444248
//CRCDEBUG_LOG(("Pathfinder::classifyFence - (%d,%d)", cellBounds.hi.x, cellBounds.hi.y));
42454249

4246-
// In retail, the values in the stack often look like this. We set them
4247-
// to reduce the likelihood of mismatch.
4248-
cellBounds.hi.x = 253961804;
4249-
cellBounds.hi.y = 4202797;
4250+
// For retail the values on the stack are often either 0 or larger than the map size.
4251+
// We initialize them to reduce the likelihood of a mismatch.
4252+
if (m_classifyFenceZeroInit)
4253+
{
4254+
cellBounds.hi.x = 0;
4255+
cellBounds.hi.y = 0;
4256+
}
4257+
else
4258+
{
4259+
cellBounds.hi.x = 1000000;
4260+
cellBounds.hi.y = 1000000;
4261+
}
42504262
#else
42514263
cellBounds.hi.x = REAL_TO_INT_CEIL((pos->x + 0.5f)/PATHFIND_CELL_SIZE_F);
42524264
cellBounds.hi.y = REAL_TO_INT_CEIL((pos->y + 0.5f)/PATHFIND_CELL_SIZE_F);

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,12 @@ void GameLogic::processDestroyList()
24892489
{
24902490
//USE_PERF_TIMER(processDestroyList)
24912491

2492+
#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
2493+
// TheSuperHackers @info Set m_classifyFenceZeroInit to true for the first object. It's set to false when this function exits.
2494+
// Pathfinder::classifyFence may be called indirectly from Object::~Object.
2495+
TheAI->pathfinder()->m_classifyFenceZeroInit = !m_objectsToDestroy.empty();
2496+
#endif
2497+
24922498
for( ObjectPointerListIterator iterator = m_objectsToDestroy.begin(); iterator != m_objectsToDestroy.end(); iterator++ )
24932499
{
24942500
Object* currentObject = (*iterator);
@@ -2547,6 +2553,10 @@ void GameLogic::processDestroyList()
25472553
removeObjectFromLookupTable( currentObject );
25482554

25492555
Object::friend_deleteInstance(currentObject);//actual delete
2556+
2557+
#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
2558+
TheAI->pathfinder()->m_classifyFenceZeroInit = false;
2559+
#endif
25502560
}
25512561

25522562
m_objectsToDestroy.clear();//list full of bad pointers now, clear it. If anyone's deletion resulted

0 commit comments

Comments
 (0)