m32script: in 'for i drawnsprites' handling, back up and restore sprite MAXSPRITES-1.

This fixes the level 5 corruption encountered when issuing that iteration.
(Because the last sprite would be changed from e.g. statnum MAXSTATUS to 0.)
It is also mandatory anyhow since the last sprite may be contained in the map.

git-svn-id: https://svn.eduke32.com/eduke32@5019 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2015-02-19 17:41:57 +00:00
parent 7742d5a40a
commit f541b96213

View file

@ -1356,16 +1356,30 @@ skip_check:
}
break;
case ITER_DRAWNSPRITES:
{
tspritetype lastSpriteBackup;
tspritetype *const lastSpritePtr = (tspritetype *)&sprite[MAXSPRITES-1];
// Back up sprite MAXSPRITES-1.
Bmemcpy(&lastSpriteBackup, lastSpritePtr, sizeof(tspritetype));
for (int ii=0; ii<spritesortcnt && !vm.flags; ii++)
{
vm.g_sp = (tspritetype *)&sprite[MAXSPRITES-1];
Bmemcpy(&sprite[MAXSPRITES-1], &tsprite[ii], sizeof(tspritetype));
vm.g_sp = lastSpritePtr;
Bmemcpy(lastSpritePtr, &tsprite[ii], sizeof(tspritetype));
Gv_SetVarX(var, ii);
insptr = beg;
VM_Execute(1);
Bmemcpy(&tsprite[ii], &sprite[MAXSPRITES-1], sizeof(tspritetype));
// Copy over potentially altered tsprite.
Bmemcpy(&tsprite[ii], lastSpritePtr, sizeof(tspritetype));
}
// Restore sprite MAXSPRITES-1.
Bmemcpy(lastSpritePtr, &lastSpriteBackup, sizeof(tspritetype));
break;
}
case ITER_SPRITESOFSECTOR:
if (parm2 < 0 || parm2 >= MAXSECTORS)
goto badindex;