From 8fe88606c68cbcd58d1fea81f63c6636fa1eda7f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 Jul 2022 16:08:40 -0300 Subject: [PATCH] Fix possible std::clamp() assert fail --- src/ui/menu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/menu.cpp b/src/ui/menu.cpp index 55565c90d..9713290a3 100644 --- a/src/ui/menu.cpp +++ b/src/ui/menu.cpp @@ -872,9 +872,9 @@ bool MenuItem::onProcessMessage(Message* msg) int x, y = bounds().y-3*guiscale(); Rect r1(0, 0, pos.w, pos.h), r2(0, 0, pos.w, pos.h); - r1.x = x_left = std::clamp(x_left, 0, ui::display_w()-pos.w); - r2.x = x_right = std::clamp(x_right, 0, ui::display_w()-pos.w); - r1.y = r2.y = y = std::clamp(y, 0, ui::display_h()-pos.h); + r1.x = x_left = std::clamp(x_left, 0, std::max(0, ui::display_w()-pos.w)); + r2.x = x_right = std::clamp(x_right, 0, std::max(0, ui::display_w()-pos.w)); + r1.y = r2.y = y = std::clamp(y, 0, std::max(0, ui::display_h()-pos.h)); // Calculate both intersections gfx::Rect s1 = r1.createIntersection(old_pos);