From 2a80c80f6c7434730256489e43746aad9ede6b0a Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 3 Apr 2020 16:28:50 -0700 Subject: [PATCH] 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. --- desktop_version/src/Input.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 16e255dc..2d30916e 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -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) {