From adb1c842c200987304e2cbe86ee6199c83ecc600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= Date: Thu, 9 Feb 2023 01:28:28 +0100 Subject: [PATCH] SoundPlayer: Fix logic bug in bars visualization When calculating bar height, we clamp our values to the maximum vertical height of the widget minus a margin. When the window was resized such that the widget got smaller than this margin however, our maximum height became negative. This caused a crash in clamp(). --- Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp b/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp index a9c2f81180..74b7c0aee3 100644 --- a/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp +++ b/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp @@ -75,7 +75,7 @@ void BarsVisualizationWidget::render(GUI::PaintEvent& event, FixedArray c int const top_vertical_margin = 15; int const pixels_inbetween_groups = frame_inner_rect().width() > 350 ? 5 : 2; int const pixel_per_group_width = (frame_inner_rect().width() - horizontal_margin * 2 - pixels_inbetween_groups * (bar_count - 1)) / bar_count; - int const max_height = frame_inner_rect().height() - top_vertical_margin; + int const max_height = AK::max(0, frame_inner_rect().height() - top_vertical_margin); int current_xpos = horizontal_margin; for (size_t g = 0; g < bar_count; g++) { m_gfx_falling_bars[g] = AK::min(clamp(max_height - static_cast(groups[g] * static_cast(max_height) * 0.8f), 0, max_height), m_gfx_falling_bars[g]);