1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Fix undefined behavior when removing activity zones

It turns out the game engaged in pseudo-UB when removing activity zones,
which got turned into actual UB due to the previous commit.

There were three places where this could happen:
 - Pressing ENTER on an activity zone in normal gameplay
 - Pressing ENTER on an activity zone in in-editor playtesting (because
   the code is duped here)
 - Pressing ESC and quitting to menu while standing inside an activity
   zone

In all cases, game.activeactivity would still be pointing to a
non-existent activity zone. This activity zone in the previous system
would simply be a block with a false 'active', and in the system where
C++ vectors are used properly, would index past the blocks array.

In fact, it is a bug that when you press ENTER on an activity zone, the
activity zone prompt suddenly turns to black, then immediately
disappears. It was pointing to a block that had its clear() method
called, which is why it was all black, and it was an inactive block!
This commit makes it so pressing ENTER on an activity zone smoothly
fades out the activity zone prompt instead of being sudden black.
This commit is contained in:
Misa 2020-04-03 16:28:50 -07:00 committed by Ethan Lee
parent f10ac88c1a
commit 2a80c80f6c

View file

@ -1717,6 +1717,7 @@ void gameinput()
{
script.load(obj.blocks[game.activeactivity].script);
obj.removeblock(game.activeactivity);
game.activeactivity = -1;
}
}else{
game.gamestate = EDITORMODE;
@ -1823,6 +1824,7 @@ void gameinput()
{
script.load(obj.blocks[game.activeactivity].script);
obj.removeblock(game.activeactivity);
game.activeactivity = -1;
}
}
else if (game.swnmode == 1 && game.swngame == 1)
@ -2058,6 +2060,7 @@ void mapinput()
FillRect(graphics.menubuffer, 0x000000);
graphics.resumegamemode = true;
obj.removeallblocks();
game.activeactivity = -1;
game.menukludge = false;
if (game.menupage >= 20)
{