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.
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 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
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.