- Blood: don't use references to address gBusy.

This will fail if the callback in trProcessBusy adds new entries to the array which would invalidate the reference.
This commit is contained in:
Christoph Oelckers 2022-01-16 12:01:53 +01:00
parent 520c03b4f1
commit 0beb91e17e

View file

@ -2130,27 +2130,27 @@ void trProcessBusy(void)
{ {
sect.velCeil = sect.velFloor = 0; sect.velCeil = sect.velFloor = 0;
} }
for (auto& b : backwards(gBusy)) for (int i = gBusy.Size(); i >= 0; i--)
{ {
int nStatus; int nStatus;
int oldBusy = b.busy; int oldBusy = gBusy[i].busy;
b.busy = ClipRange(oldBusy + b.delta * 4, 0, 65536); gBusy[i].busy = ClipRange(oldBusy + gBusy[i].delta * 4, 0, 65536);
#ifdef NOONE_EXTENSIONS #ifdef NOONE_EXTENSIONS
if (!gModernMap || !b.sect->xs().unused1) nStatus = gBusyProc[b.type](b.sect, b.busy); if (!gModernMap || !gBusy[i].sect->xs().unused1) nStatus = gBusyProc[gBusy[i].type](gBusy[i].sect, gBusy[i].busy);
else nStatus = 3; // allow to pause/continue motion for sectors any time by sending special command else nStatus = 3; // allow to pause/continue motion for sectors any time by sending special command
#else #else
nStatus = gBusyProc[b.type](b.at0, b.at8); nStatus = gBusyProc[gBusy[i].type](gBusy[i].at0, gBusy[i].at8);
#endif #endif
switch (nStatus) { switch (nStatus) {
case 1: case 1:
b.busy = oldBusy; gBusy[i].busy = oldBusy;
break; break;
case 2: case 2:
b.busy = oldBusy; gBusy[i].busy = oldBusy;
b.delta = -b.delta; gBusy[i].delta = -gBusy[i].delta;
break; break;
case 3: case 3:
b = gBusy.Last(); gBusy[i] = gBusy.Last();
gBusy.Pop(); gBusy.Pop();
break; break;
} }