Callback crashes when button released

Description

I am new to LVGL and may have misunderstood something. I am trying to use callbacks to increment and decrement a float when the button is pressed. The float does indeed increment and decrement correctly but it then crashes when you release the button. If you change LV_EVENTS_PRESSED to PRESSING it will continually change the float but again will crash the moment you release the button.

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

I am using a WT32 SC01 Plus display that has a ESP32S3 and PlatfromIO

What LVGL version are you using?

8.3.6

What do you want to achieve?

Stop it crashing :slight_smile:

What have you tried so far?

Code to reproduce

in main.cpp the callbacks are

lv_obj_add_event_cb(ui_ButTimeP, tIncrease, LV_EVENT_PRESSED, &TargetTime);
lv_obj_add_event_cb(ui_ButTimeM, tDecrease, LV_EVENT_PRESSED, &TargetTime);

the float to change is TargetTime

in ui_events.c

void tDecrease(lv_event_t * e)
{
float* pointer = lv_event_get_user_data(e);
(*pointer)-=0.1;
}

void tIncrease(lv_event_t * e)
{
float* pointer = lv_event_get_user_data(e);
(*pointer)+=0.1;
}

Maybe your code crash on other place. And too your code is waste of res. Dont use userdata here. Simply manipulate in cb directly TargetTime global variable.

Found it. Hopefully this will help someone else that is also learning.

Short story, if you edit ui.events.c you must comment out the squareline created add event cb in ui.#insert screen name#.c

Long story

Squareline Studio creates a callback event in ui.#insert screen name#.c and it passes NULL. Untouched this is fine but when you edit the functions ui_events.c it is not fine. We have modified ui_events.c to do math on what is passed in and you obviously can’t add or subtract from NULL.

So why does it only crash when you release the button? In ui.c we have another bit of Squareline generated code

void ui_event_ButTimeM(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_PRESSED) {
tDecrease(e);
}

It is conditioned on PRESSED and so only runs when the button is release.

I am new to this and it is probably obvious to the more experienced.

Well my code is working so on we press. Good luck everyone…