mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
Duke3d: this is intended to fix an issue where CON VM errors within a CON_FOR loop could cause an infinite loop
This commit is contained in:
parent
8cf064b90c
commit
c0160065e4
1 changed files with 34 additions and 21 deletions
|
@ -2727,14 +2727,6 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
dispatch();
|
||||
}
|
||||
|
||||
#define CON_FOR_ITERATION() \
|
||||
do \
|
||||
{ \
|
||||
Gv_SetVar(returnVar, jj); \
|
||||
insptr = pNext; \
|
||||
VM_Execute(); \
|
||||
} while (0)
|
||||
|
||||
vInstruction(CON_FOR): // special-purpose iteration
|
||||
insptr++;
|
||||
{
|
||||
|
@ -2745,6 +2737,13 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
auto const pEnd = insptr + *insptr;
|
||||
auto const pNext = ++insptr;
|
||||
|
||||
auto execute = [&](int index) {
|
||||
Gv_SetVar(returnVar, index);
|
||||
insptr = pNext;
|
||||
VM_Execute();
|
||||
return !!(vm.flags & VM_RETURN);
|
||||
};
|
||||
|
||||
switch (iterType)
|
||||
{
|
||||
case ITER_ALLSPRITES:
|
||||
|
@ -2752,7 +2751,9 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
{
|
||||
if (sprite[jj].statnum == MAXSTATUS)
|
||||
continue;
|
||||
CON_FOR_ITERATION();
|
||||
|
||||
if (execute(jj))
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2760,7 +2761,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
for (native_t statNum = 0; statNum < MAXSTATUS; ++statNum)
|
||||
{
|
||||
for (native_t kk, SPRITES_OF_STAT_SAFE(statNum, jj, kk))
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2768,18 +2770,21 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
for (native_t sectNum = 0; sectNum < numsectors; ++sectNum)
|
||||
{
|
||||
for (native_t kk, SPRITES_OF_SECT_SAFE(sectNum, jj, kk))
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITER_ALLSECTORS:
|
||||
for (native_t jj = 0; jj < numsectors; ++jj)
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
|
||||
case ITER_ALLWALLS:
|
||||
for (native_t jj = 0; jj < numwalls; ++jj)
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
|
||||
case ITER_ACTIVELIGHTS:
|
||||
|
@ -2788,14 +2793,17 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
{
|
||||
if (!prlights[jj].flags.active)
|
||||
continue;
|
||||
CON_FOR_ITERATION();
|
||||
|
||||
if (execute(jj))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case ITER_DRAWNSPRITES:
|
||||
for (native_t jj = 0; jj < spritesortcnt; jj++)
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
|
||||
case ITER_SPRITESOFSECTOR:
|
||||
|
@ -2803,7 +2811,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
goto badindex;
|
||||
|
||||
for (native_t kk, SPRITES_OF_SECT_SAFE(nIndex, jj, kk))
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
|
||||
case ITER_SPRITESOFSTATUS:
|
||||
|
@ -2811,7 +2820,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
goto badindex;
|
||||
|
||||
for (native_t kk, SPRITES_OF_STAT_SAFE(nIndex, jj, kk))
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
|
||||
case ITER_WALLSOFSECTOR:
|
||||
|
@ -2819,7 +2829,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
goto badindex;
|
||||
|
||||
for (native_t jj = sector[nIndex].wallptr, endwall = jj + sector[nIndex].wallnum - 1; jj <= endwall; jj++)
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
|
||||
case ITER_LOOPOFWALL:
|
||||
|
@ -2829,7 +2840,9 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
int jj = nIndex;
|
||||
do
|
||||
{
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
|
||||
jj = wall[jj].point2;
|
||||
} while (jj != nIndex);
|
||||
}
|
||||
|
@ -2837,7 +2850,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/)
|
|||
|
||||
case ITER_RANGE:
|
||||
for (native_t jj = 0; jj < nIndex; jj++)
|
||||
CON_FOR_ITERATION();
|
||||
if (execute(jj))
|
||||
return;
|
||||
break;
|
||||
badindex:
|
||||
Printf(OSD_ERROR "Line %d, for %s: index %d out of range!\n", VM_DECODE_LINE_NUMBER(g_tw), iter_tokens[iterType].token, nIndex);
|
||||
|
@ -2847,7 +2861,6 @@ badindex:
|
|||
insptr = pEnd;
|
||||
}
|
||||
dispatch();
|
||||
#undef CON_FOR_ITERATION
|
||||
|
||||
vInstruction(CON_REDEFINEQUOTE):
|
||||
insptr++;
|
||||
|
|
Loading…
Reference in a new issue