Callback crashes when button released - newbie

What do you want to achieve?

Increment and decrement a float.

What have you tried so far?

I have declared the float as a global and setup the callbacks as below. Pressing the + or - button changes the float value BUT when I release the button it crashes.

I have created the callbacks in setup:

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

in events.c I have the call back functions

void tDecrease(lv_event_t * e)
float* pointer = lv_event_get_user_data(e);

void tIncrease(lv_event_t * e)
float* pointer = lv_event_get_user_data(e);

Changing LV_EVENT_PRESSED to PRESSING leads to the value continually changing as expected but again it crashes when you release the button.

Screenshot or video


  • **SquareLine Studio version: 1.4
  • **Operating system: 11 Pro 23H2
  • **Target hardware: WT32 SC01 Plus

It’s very interesting, it shouldn’t behave like this. Releasing the buttons triggers event when LV_EVENT_CLICKED is set, but I guess you don’t have such kind of function left there. Crashes are usually done when some object to be modified doesn’t exist, but maybe it’s other problem in your case. Hopefully your variable you set has the same ‘float’ type as the ‘pointer’ in your callbacks (and not ‘double’). Hopefully it’s not a memory-config issue in lv_conf.h From this small code-snippet none of these circumstances are seen.
Anyway, it would be enlightening if you somehow get some debugging info / backtrace which shows where and what kind of crash (SEGFAULT/whatever?) happens.

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

Short story, if you edit 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) {

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…

Thanks for sharing your solution and experience with the community. If you need to pass that user-data parameter instead of NULL (as in e.g. ‘ui_Screen1.c’), i think it’s better if you don’t create any event for the button in SquareLine Studio but add it in your code when the screen containing the button is loaded. (It’s advisable to first delete the previously set callback, so it doesn’t get accumulated, no matter what.)
This way you avoid the need to edit exported UI-files (inside ‘ui’ folder) which can be overwritten on a new export from SquareLine Studio.