From fe821204a79bba88b520e55973bcc2e8535348a5 Mon Sep 17 00:00:00 2001 From: Liam <30486941+liamHowatt@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:47:46 -0400 Subject: [PATCH] fix(roller): avoid divided-by-zero during draw event (#6285) (#6661) Co-authored-by: ymh-masuda <160470322+ymh-masuda@users.noreply.github.com> --- src/widgets/roller/lv_roller.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/widgets/roller/lv_roller.c b/src/widgets/roller/lv_roller.c index 392044735b..188777d1cb 100644 --- a/src/widgets/roller/lv_roller.c +++ b/src/widgets/roller/lv_roller.c @@ -473,7 +473,10 @@ static void draw_main(lv_event_t * e) /*Proportional position from the middle line. *Will be 0 for the first option, and 1 for the last option (upscaled by << 14)*/ - label_y_prop = (label_y_prop << 14) / (lv_obj_get_height(label) - normal_label_font->line_height); + int32_t remain_h = lv_obj_get_height(label) - normal_label_font->line_height; + if(remain_h > 0) { + label_y_prop = (label_y_prop << 14) / remain_h; + } /*We don't want the selected label start and end exactly where the normal label is as *a larger font won't centered on selected area.*/