From 994b3602e580cf7e68e61b3965144dd1e94bd196 Mon Sep 17 00:00:00 2001 From: NyakoFox Date: Sat, 11 Apr 2026 15:26:38 -0300 Subject: [PATCH] Clamp editor mouse coordinates The editor has never clamped mouse bounds, and instead relied on SDL to return clamped mouse coordinates. Unfortunately, in #1140, this detail was missed, and the behavior changed, allowing the cursor to leave the bounds of the screen. This isn't much of a problem most of the time because anything that uses position as array indeces has bounds checks. Unfortunately, placing entities outside of a room's bounds leads to entities you can't ever touch ever again without modifying the level externally. This is the worst with checkpoints, as pressing Enter in a room will now take you to the out-of-bounds checkpoint, causing you to immediately wrap to another room. This fix should be backported to 2.4, as the issue can lead to level files which need manual editing to fix! --- desktop_version/src/Editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/Editor.cpp b/desktop_version/src/Editor.cpp index fe89d98d..44cb0d39 100644 --- a/desktop_version/src/Editor.cpp +++ b/desktop_version/src/Editor.cpp @@ -3206,8 +3206,8 @@ void editorinput(void) ed.old_tilex = ed.tilex; ed.old_tiley = ed.tiley; - ed.tilex = key.mousex / 8; - ed.tiley = key.mousey / 8; + ed.tilex = SDL_clamp(key.mousex, 0, SCREEN_WIDTH_PIXELS - 1) / 8; + ed.tiley = SDL_clamp(key.mousey, 0, SCREEN_HEIGHT_PIXELS - 1) / 8; bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_UP); bool down_pressed = key.isDown(SDLK_DOWN) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_DOWN);