How to switch themes realtime, why it bootloops?

What do you want to achieve?

I want to change between themes dynamically from a dropdown checkbox.

What have you tried so far?

I added themes on SquareLine Studio UI, added a dropdown menu containing my 2 theme names. I added colors to these themes (button border, button background, label text color etc.).
I added an event if the dropdown value change, call my function:

void theme_dropdown_change_event(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_VALUE_CHANGED) {
    uint8_t theme_index = lv_dropdown_get_selected(target);
    ui_theme_set(theme_index);
  }
}

but when i change the value it does not change theme (so ie. button border color does not change). What i am doing wrong?

Screenshot or video

Others

  • SquareLine Studio version: 1.4.2
  • Operating system: macOS
  • Target hardware: WT32-SC01-Plus

so, added more colors and theme set on all screens for all components, now the ESP32-S3 does not start, it goes bootloop. Here is the coredump:

ELF file SHA256: 2594c914f41883b2

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x9 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40377d34
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a80
entry 0x403c98d0
E (12316) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (12316) task_wdt:  - IDLE (CPU 0)
E (12316) task_wdt: Tasks currently running:
E (12316) task_wdt: CPU 0: loopTask
E (12316) task_wdt: CPU 1: IDLE
E (12316) task_wdt: Aborting.

abort() was called at PC 0x42046188 on core 0

i do not know why this is happening… do you have any idea?

update: i tried to add the theme 1 by 1 to the screens, and it seems for 1 screen with 8 components the ESP32 starts smoothly. For 2 screens, the main screen starts but then goes to bootloop. So, does it something with watchdog timers? It could not reset it because switching to themes took so long, that is why the restarts?

update2: commented out ui_object_set_themeable_style_property seems solves the problem - the esp32 starts - but with default global theme on the widgets and components. So no theme switching, still… And this reminds me the following bug here on this forum: Themes Drastically slowing down Screen/Component Generation
but in my case, setting LV_SQUARELINE_THEME__OBJECT_VALIDITY_CACHE does not solve the problem :frowning: My company had high hopes in this theme switching function though…

If you wait a little bit there will be an update in which the theme-handling is made much faster by a different garbage collector approach (mentioned in the linked topic). So don’t give up yet, it should work, at least it worked fine in some of our service-projects on several-hundred MHz boards. Also, if the boot-loop depends on the amount of screens/widgets, you might need to check LV_MEM_CUSTOM / LV_MEM_SIZE in lv_conf.h, if the boot-loop is not caused by some memory-overflow. (Another tip: If you use temporary screens you can boot up faster and use much less memory in a many-screens project, if that counts.)

Thank you for the quick response.

These are great news! I’ll try the LV_MEM thing, but how to create dynamic screens with SquareLine Studio? Just remove the screen initialization from the ui_init() and leave the touch button events to create the screens? In this case what will guarantee the garbage collection of unactive screens?

The ‘temporary screen’ selection is built into the SquareLine Studio Inspector panel, and in the exported code the screens won’t be initialized (created) in ui_init and they get an undelete callback in their initialization code, if that tickbox is checked. That deletes them when they’re unloaded by changing to another screen, and the rest of the garbage collection (deleting children too) is done by LVGL automatically then. (Except animations and maybe some other special cases.)

Hi @Hermit , i see there is a new release from SquarelineStudio (1.5.0). Is this something that you mentioned in your previous comment that tries to fix theme performance?
Should i use newer LVGL version with that (ie. 9)? I am asking because previously tried LVGL9 but unfortunately they removed lv_colorwheel which is a must in my project, so i switched back to the latest 8 (8.4.0).

Yes, you should definitely try the new teme handling performance and we are interested in your feedback too. Don’t worry, it will work pretty much the same on both LVGL8 and LVGL9.
(Btw I added a more detailed description for the new garbage collector at Themes Drastically slowing down Screen/Component Generation - #10 by Hermit )

Sorry for the late response here.

So we tried the new theme handling and it works like a charm! The theme manager code that is generated by SLS 1.5.0 had some issues (ie. when the ESP32 started, sometimes got reset twice or 3 times when finally managed to start properly - sometimes it took 20-30sec to set up - so it was quite unreliable on WT32-SC01-plus display). But 1.5.1 generates proper theme manager code and the ESP32 starts immediately showing the logo screen, so awesome work folks!

1 Like