Add bound checking to Simulation::clear_area

Fixes a crash easily reproducible with sim.clearRect(-10000000, -10000000, 20000000, 20000000)
This commit is contained in:
Tamás Bálint Misius 2023-10-09 23:46:53 +02:00
parent b2045c067e
commit 04b8378de4
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -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++)
{