Lv_led issue: crash if brightness < 100 due to shadow, arose when porting from 5.3 to 6.1.2

Description

System crashes when rendering an LED

What MCU/Processor/Board and compiler are you using?

PSoC 6 - CY8PROTO-063

What do you experience?

I’m getting a crash due to an LED shadow width getting set to a negative number. The offending code is:

    leds_tmp.body.shadow.width =
        ((bright_tmp - LV_LED_BRIGHT_OFF) * style->body.shadow.width) / (LV_LED_BRIGHT_ON - LV_LED_BRIGHT_OFF);

I’ve set the brightness to 20, but LV_LED_BRIGHT_OFF is 100.

This was a bit of a bear to find :slight_smile:

What do you expect?

I expected the port to work as did v5.3

Code to reproduce

        lv_style_copy(&style_led, &lv_style_pretty_color);
        style_led.body.radius       = LV_RADIUS_CIRCLE;
        style_led.body.main_color   = LV_COLOR_MAKE(0x04, 0x0f, 0xb5);
        style_led.body.grad_color   = LV_COLOR_MAKE(0x02, 0x07, 0x50);
        style_led.body.border.color = LV_COLOR_MAKE(0x00, 0x0f, 0xfa);
        style_led.body.border.width = 3;
        style_led.body.border.opa   = LV_OPA_30;
        style_led.body.shadow.color = LV_COLOR_MAKE(0x04, 0x0f, 0xb5);
        style_led.body.shadow.width = 10;

            /*Create a LED and switch it ON*/
        int i = 0;
        led_arr[i] = lv_led_create(my_btn, NULL);
        lv_obj_set_size(led_arr[i], 25, 25);
        lv_obj_set_style(led_arr[i], &style_led);
        lv_obj_align(led_arr[i], NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 50);
        lv_led_set_bright( led_arr[i], 20 );

Screenshot and/or video

image

Parenthetically, I looked at my 5.3.0 environment, and I don’t know why this problem did not occur then!

Thanks for the report!
I’m thinking about a solution to add LV_LED_BRIGHT_OFF a LV_LED_BRIGHT_ON to lv_conf.h and limit the value in lv_led_set_bright.
What do you think?

Dear Gabor,

First I want to thank you for creating LittleVGL! It satisfies a real need in embedded computing. These small graphics touch-displays are very affordable, and this makes it relatively easy to create inexpensive, user-friendly devices using Cortex-M class CPUs. I teach a course in Embedded Systems and I’m thinking of introducing LVGL next semester, and I’m giving a talk at TCF (tcf-nj DOT org) that will introduce LVGL.

If I understand your proposal correctly it would guarantee that the current problem can’t occur, as it would clip whatever value set for an LED to the _ON and _OFF levels. That sounds reasonable to me.

Kind regards,

Larry

That’s awesome! I’ve checked the schedule of TCF here. Which one is the related talk?

I’ve just fixed it in dev-7.0. It will be part of the next version.

T-COM: A Low-Power Networked Mobile Health DeviceL. Pearlstein, J Sinoway

1 Like