Storing widget objects in an array causing a crash on boot

What do you want to achieve?

Hello, love what I’ve used so far of Squareline. I’m having an issue where I’m trying to store objects as a getter-accessed parameter of a class of custom objects in an array in a state.h/state.cpp file so that I can access them programatically. Doing this is causing my hardware (an m5stack core2) to crash on boot constantly. I’ve appended the relevant code below: Any help would be greatly appreciated!

What have you tried so far?

beacon.h

class beacon {
  public:
  beacon(double lat, double lng, lv_obj_t * arc, lv_obj_t * lock, lv_obj_t * lockOpen, lv_obj_t * status, lv_obj_t * distance);
  lv_obj_t * ui(String el);                         // Returns a LVGL ui element
  private:
    lv_obj_t * _ui_arc;
    lv_obj_t * _ui_lock;
    lv_obj_t * _ui_lockOpen;
    lv_obj_t * _ui_status;
    lv_obj_t * _ui_distance;
    double _lat;
    double _lng;
    bool _isInRange;
    byte _unlockPercent;  
};

beacon.cpp

beacon::beacon(double lat, double lng, lv_obj_t * arc, lv_obj_t * lock, lv_obj_t * lockOpen, lv_obj_t * status, lv_obj_t * distance) {
  _lat = lat;
  _lng = lng;
  _isInRange = false;
  _unlockPercent=0;
  _unlockedAt = 0;
  _ui_arc=arc;
  _ui_lock=lock;
  _ui_lockOpen=lockOpen;
  _ui_status=status;
  _ui_distance=distance;  
};

lv_obj_t * beacon::ui(String el) {
  return _ui_arc; // will break this down when working
}

state.h
extern beacon beacons[3];

state.cpp

static beacon beacon1(-33.91, 151.10,ui_beaconArc1,ui_beaconLock1,ui_beaconLockOpen1,ui_beaconStatus1,ui_beaconDistance1);
static beacon beacon2(-33.91, 151.10,ui_beaconArc2,ui_beaconLock2,ui_beaconLockOpen2,ui_beaconStatus2,ui_beaconDistance2);
static beacon beacon3(-33.91, 151.10,ui_beaconArc3,ui_beaconLock3,ui_beaconLockOpen3,ui_beaconStatus3,ui_beaconDistance3
);
beacon beacons[]={beacon1,beacon2,beacon3};

main.cpp

void ui_reset() {
    for (beacon b : beacons) {
    if (not true) {
      lv_arc_set_value(beacons[0].ui("arc"),0);    // this causes the crash
    } else {
      lv_arc_set_value(ui_beaconArc1,50);   // this doesn't
    }
    //   lv_label_set_text_fmt(b.ui_distance, "???");
  }

void setup() {
  ...
  lv_init();                    // initialise LVGL
  lv_disp_draw_buf_init(&draw_buf,b1,b2,(screenWidth*screenHeight)/10);
  init_display();
  init_touch();
  ui_init();                    // initialise the Squareline design
  ui_reset();

Others

  • SquareLine Studio version: latest running LVGL 8.2
  • Operating system: PC (VSC/platformio)
  • Target hardware: M5Stack Core2

This creates the arrays before ui_init() is called and therefore ui_beaconLock1 is still NULL when you save it’s value.

You can either

  1. Create these instances after ui_init()
  2. Save e.g. &ui_beaconLock1 in lv_obj_t **. This way you will always see the the current value of the original ui_variables and not only “snapshot”.

Oh my god, of course. Thanks so much, I’ve been trying to get this working for a day and a half.

1 Like

Glad that I could help :slight_smile:

1 Like