Change / Delete Images causes ESP32 to crash

I’m trying to change images in run-time. Basically a image that will change depending on the Battery Level. Problem is, When I either:

  • Try to change the image directly
  • Delete the Object

My Device (ESP32) crashes with the following:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4204bed7  PS      : 0x00060630  A0      : 0x82004294  A1      : 0x3fcebb50  
A2      : 0x00000000  A3      : 0x00ffffff  A4      : 0x80377fa7  A5      : 0x3fcf4bf0  
A6      : 0x00000001  A7      : 0x3fce9dc0  A8      : 0x00000020  A9      : 0x80000000  
A10     : 0x3fca4ccc  A11     : 0x3fca4ccc  A12     : 0x80000020  A13     : 0x00000007  
A14     : 0x00000005  A15     : 0x00000001  SAR     : 0x0000001a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000008  LBEG    : 0x4200c7b4  LEND    : 0x4200c7d2  LCOUNT  : 0x00000000  


Backtrace: 0x4204bed4:0x3fcebb50 0x42004291:0x3fcebb70 0x420075fd:0x3fcebba0 0x42001f59:0x3fcebbc0 0x420020a3:0x3fcebbe0 0x4202919e:0x3fcebc50

Part of my code is this (took all of the unimportant stuff):

float perc = 5;
lv_obj_t * batteryLevelImg;
LV_IMG_DECLARE(BatteryFull);
LV_IMG_DECLARE(BatteryHalf);
LV_IMG_DECLARE(BatteryLow);
LV_IMG_DECLARE(BatteryEmpty);

void setup() {
....
BatterySetup();

    delay( 500 );
    //BatteryLevelImage();
}

void BatterySetup() {
    lv_obj_t * batteryLevelImg = lv_img_create(lv_scr_act());
    lv_img_set_src(batteryLevelImg, &BatteryFull);
    lv_obj_align(batteryLevelImg, LV_ALIGN_CENTER, 0, -70);
}

void BatteryLevelImage() {
    lv_obj_del(batteryLevelImg);
    delay(50);

    /*if (perc < 10) {
        lv_img_set_src(batteryLevelImg, &BatteryEmpty);
    } else if (perc < 30)
    {
        lv_img_set_src(batteryLevelImg, &BatteryLow);
    } else if (perc < 80)
    {
        lv_img_set_src(batteryLevelImg, &BatteryHalf);
    } else {
        lv_img_set_src(batteryLevelImg, &BatteryFull);
    }*/
}

Crash happens on BatteryLevelImage(). Both lv_img_set_src() to the existing variables, as well as deleting the image object result in a crash.
Creating more images are not a problem, but removing / changing the old ones are!

The images are 32x32 pixels CF_TRUE_COLOR and the C array files are about 57Kb.
So I’d be willing to say it’s not a memory Issue.

Solved… It’s F%%&%& pointers!

lv_obj_t * batteryLevelImg;

void BatterySetup() {
    lv_obj_t * batteryLevelImgHolder = lv_img_create(lv_scr_act()); //Pointer
    batteryLevelImg = batteryLevelImgHolder; //Add the Pointer to the Variable in the declaration
    lv_img_set_src(batteryLevelImgHolder, &BatteryFull);
    lv_obj_align(batteryLevelImgHolder, LV_ALIGN_CENTER, 0, -70);
}

void BatteryLevelImage() {
    if (perc < 10) {
        lv_img_set_src(batteryLevelImg, &BatteryEmpty);
    } else if (perc < 30)
    {
        lv_img_set_src(batteryLevelImg, &BatteryLow);
    } else if (perc < 80)
    {
        lv_img_set_src(batteryLevelImg, &BatteryHalf);
    } else {
        lv_img_set_src(batteryLevelImg, &BatteryFull);
    }
}

C… :zipper_mouth_face:

lv_obj_t * batteryLevelImg;

void BatterySetup() {
    batteryLevelImg = lv_img_create(lv_scr_act()); //Pointer
    lv_img_set_src(batteryLevelImg, &BatteryFull);
    lv_obj_align(batteryLevelImg, LV_ALIGN_CENTER, 0, -70);
}

void BatteryLevelImage() {
    if (perc < 10) {
        lv_img_set_src(batteryLevelImg, &BatteryEmpty);
    } else if (perc < 30)
    {
        lv_img_set_src(batteryLevelImg, &BatteryLow);
    } else if (perc < 80)
    {
        lv_img_set_src(batteryLevelImg, &BatteryHalf);
    } else {
        lv_img_set_src(batteryLevelImg, &BatteryFull);
    }
}