From 04b8378de4c6d9da07e148a09a65c8e08c2af900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Mon, 9 Oct 2023 23:46:53 +0200 Subject: [PATCH] Add bound checking to Simulation::clear_area Fixes a crash easily reproducible with sim.clearRect(-10000000, -10000000, 20000000, 20000000) --- src/simulation/Editing.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/simulation/Editing.cpp b/src/simulation/Editing.cpp index ad6556705..2c38765e0 100644 --- a/src/simulation/Editing.cpp +++ b/src/simulation/Editing.cpp @@ -85,6 +85,11 @@ void Simulation::Restore(const Snapshot &snap) void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h) { + auto intersection = RES.OriginRect() & RectSized(Vec2{ area_x, area_y }, Vec2{ area_w, area_h }); + area_x = intersection.TopLeft.X; + area_y = intersection.TopLeft.Y; + area_w = intersection.Size().X; + area_h = intersection.Size().Y; float fx = area_x-.5f, fy = area_y-.5f; for (int i = 0; i <= parts_lastActiveIndex; i++) {