From a7ae1012e52fd3a0d2f5d159edd4075d3c51c18c Mon Sep 17 00:00:00 2001 From: YgorSouza <43298013+YgorSouza@users.noreply.github.com> Date: Thu, 14 Aug 2025 10:41:51 +0200 Subject: [PATCH] Fix debug-panic in ScrollArea if contents fit without scrolling (#7440) If the ScrollArea's contents are smaller than the inner rect, but the scrollbar is set to always visible, clicking on it led to a remap from an empty range to calculate the new offset, which triggered a debug assertion in the remap function, because the result is indeterminate. Since in this case there is no need to scroll, we just skip the remap and set the offset to 0 directly. * Closes * [x] I have followed the instructions in the PR template --- crates/egui/src/containers/scroll_area.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index dbefe018..3d8bf75f 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -1315,11 +1315,13 @@ impl Prepared { }); let new_handle_top = pointer_pos[d] - *scroll_start_offset_from_top_left; - state.offset[d] = remap( - new_handle_top, - scroll_bar_rect.min[d]..=(scroll_bar_rect.max[d] - handle_rect.size()[d]), - 0.0..=max_offset[d], - ); + let handle_travel = + scroll_bar_rect.min[d]..=(scroll_bar_rect.max[d] - handle_rect.size()[d]); + state.offset[d] = if handle_travel.start() == handle_travel.end() { + 0.0 + } else { + remap(new_handle_top, handle_travel, 0.0..=max_offset[d]) + }; // some manual action taken, scroll not stuck state.scroll_stuck_to_end[d] = false;