Skip to content

Commit b76ba84

Browse files
authored
[GEN][ZH] Refactor GameLogic::rebalanceChildSleepyUpdate to avoid "vector subscript out of range" debug error (#644)
1 parent 24f057a commit b76ba84

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2504,9 +2504,9 @@ Int GameLogic::rebalanceChildSleepyUpdate(Int i)
25042504
UpdateModulePtr* pI = &m_sleepyUpdates[i];
25052505

25062506
// our children are i*2 and i*2+1
2507-
Int child = ((i+1)<<1)-1;
2508-
UpdateModulePtr* pChild = &m_sleepyUpdates[child];
2509-
UpdateModulePtr* pSZ = &m_sleepyUpdates[m_sleepyUpdates.size()]; // yes, this is off the end.
2507+
Int child = ((i)<<1)+1;
2508+
UpdateModulePtr* pChild = &m_sleepyUpdates[0] + child;
2509+
UpdateModulePtr* pSZ = &m_sleepyUpdates[0] + m_sleepyUpdates.size(); // yes, this is off the end.
25102510

25112511
while (pChild < pSZ)
25122512
{
@@ -2536,13 +2536,13 @@ Int GameLogic::rebalanceChildSleepyUpdate(Int i)
25362536
i = child;
25372537
pI = pChild;
25382538

2539-
child = ((i+1)<<1)-1;
2540-
pChild = &m_sleepyUpdates[child];
2539+
child = ((i)<<1)+1;
2540+
pChild = &m_sleepyUpdates[0] + child;
25412541
}
25422542
#else
25432543
// our children are i*2 and i*2+1
25442544
Int sz = m_sleepyUpdates.size();
2545-
Int child = ((i+1)<<1)-1;
2545+
Int child = ((i)<<1)+1;
25462546
while (child < sz)
25472547
{
25482548
// choose the higher-priority of the two children; we must be higher-pri than that.
@@ -2565,7 +2565,7 @@ Int GameLogic::rebalanceChildSleepyUpdate(Int i)
25652565
a->friend_setIndexInLogic(i);
25662566
b->friend_setIndexInLogic(child);
25672567
i = child;
2568-
child = ((i+1)<<1)-1;
2568+
child = ((i)<<1)+1;
25692569
}
25702570
#endif
25712571
return i;

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2834,9 +2834,9 @@ Int GameLogic::rebalanceChildSleepyUpdate(Int i)
28342834
UpdateModulePtr* pI = &m_sleepyUpdates[i];
28352835

28362836
// our children are i*2 and i*2+1
2837-
Int child = ((i+1)<<1)-1;
2838-
UpdateModulePtr* pChild = &m_sleepyUpdates[child];
2839-
UpdateModulePtr* pSZ = &m_sleepyUpdates[m_sleepyUpdates.size()]; // yes, this is off the end.
2837+
Int child = ((i)<<1)+1;
2838+
UpdateModulePtr* pChild = &m_sleepyUpdates[0] + child;
2839+
UpdateModulePtr* pSZ = &m_sleepyUpdates[0] + m_sleepyUpdates.size(); // yes, this is off the end.
28402840

28412841
while (pChild < pSZ)
28422842
{
@@ -2866,13 +2866,13 @@ Int GameLogic::rebalanceChildSleepyUpdate(Int i)
28662866
i = child;
28672867
pI = pChild;
28682868

2869-
child = ((i+1)<<1)-1;
2870-
pChild = &m_sleepyUpdates[child];
2869+
child = ((i)<<1)+1;
2870+
pChild = &m_sleepyUpdates[0] + child;
28712871
}
28722872
#else
28732873
// our children are i*2 and i*2+1
28742874
Int sz = m_sleepyUpdates.size();
2875-
Int child = ((i+1)<<1)-1;
2875+
Int child = ((i)<<1)+1;
28762876
while (child < sz)
28772877
{
28782878
// choose the higher-priority of the two children; we must be higher-pri than that.
@@ -2895,7 +2895,7 @@ Int GameLogic::rebalanceChildSleepyUpdate(Int i)
28952895
a->friend_setIndexInLogic(i);
28962896
b->friend_setIndexInLogic(child);
28972897
i = child;
2898-
child = ((i+1)<<1)-1;
2898+
child = ((i)<<1)+1;
28992899
}
29002900
#endif
29012901
return i;

0 commit comments

Comments
 (0)