Skip to content

fix(theme): add reentrancy guard to resolution_change_event_cb#10051

Open
catellie wants to merge 1 commit into
lvgl:masterfrom
catellie:fix/theme-default-reentrancy-guard
Open

fix(theme): add reentrancy guard to resolution_change_event_cb#10051
catellie wants to merge 1 commit into
lvgl:masterfrom
catellie:fix/theme-default-reentrancy-guard

Conversation

@catellie
Copy link
Copy Markdown

@catellie catellie commented May 4, 2026

Summary

resolution_change_event_cb (added in #9048) calls lv_theme_default_init(), which refreshes all widget styles. The style refresh marks layouts dirty and emits display events, which re-enter resolution_change_event_cb -- causing infinite recursion.

On ESP32 this overflows the stack within seconds and triggers a task watchdog timeout. Reproducible on any ESP32-S3 running ESPHome with LVGL v9.5.0 when lv_display_set_resolution() is called during setup.

Fix

Add a static bool reentrancy guard to skip reentrant calls. Minimal, zero-overhead when not recursing.

Test plan

  • Verified on ESP32-S3 (Guition 4848S040C) with ESPHome -- device boots cleanly with this patch where it previously crashed with task_wdt timeout.
  • No behavioral change for non-reentrant code paths (the guard is only hit during the recursive call).

Fixes #9982

lv_theme_default_init() refreshes all widget styles, which marks
layouts dirty and emits display events. When called from
resolution_change_event_cb this creates infinite recursion:

  resolution_change_event_cb
    -> lv_theme_default_init
      -> style refresh -> layout dirty -> display event
        -> resolution_change_event_cb  (reentrant)

On constrained devices (ESP32) this overflows the stack within
seconds, triggering a task watchdog timeout.

Add a static bool guard so reentrant calls are skipped.

Fixes lvgl#9982
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Hi 👋, thank you for your PR!

We've run benchmarks in an emulated environment. Here are the results:

ARM Emulated 32b - lv_conf_perf32b

Scene Name Avg CPU (%) Avg FPS Avg Time (ms) Render Time (ms) Flush Time (ms)
All scenes avg. 27 37 7 7 0
Detailed Results Per Scene
Scene Name Avg CPU (%) Avg FPS Avg Time (ms) Render Time (ms) Flush Time (ms)
Empty screen 11 33 0 0 0
Moving wallpaper 2 33 1 1 0
Single rectangle 0 50 0 0 0
Multiple rectangles 0 33 0 0 0
Multiple RGB images 0 39 0 0 0
Multiple ARGB images 10 41 3 3 0
Rotated ARGB images 55 (-1) 44 15 15 0
Multiple labels 6 35 0 0 0
Screen sized text 81 45 17 17 0
Multiple arcs 40 33 7 7 0
Containers 4 37 0 0 0
Containers with overlay 86 21 44 44 0
Containers with opa 17 37 1 1 0
Containers with opa_layer 18 34 5 5 0
Containers with scrolling 44 45 12 12 0
Widgets demo 71 39 16 16 0
All scenes avg. 27 37 7 7 0

ARM Emulated 64b - lv_conf_perf64b

Scene Name Avg CPU (%) Avg FPS Avg Time (ms) Render Time (ms) Flush Time (ms)
All scenes avg. 25 37 6 6 0
Detailed Results Per Scene
Scene Name Avg CPU (%) Avg FPS Avg Time (ms) Render Time (ms) Flush Time (ms)
Empty screen 11 33 0 0 0
Moving wallpaper 1 33 0 0 0
Single rectangle 0 50 0 0 0
Multiple rectangles 0 35 0 0 0
Multiple RGB images 0 39 0 0 0
Multiple ARGB images 11 42 0 0 0
Rotated ARGB images 29 33 9 9 0
Multiple labels 2 35 0 0 0
Screen sized text 85 46 18 18 0
Multiple arcs 33 33 6 6 0
Containers 4 37 0 0 0
Containers with overlay 98 22 42 42 0
Containers with opa 15 (-1) 38 (+2) 0 0 0
Containers with opa_layer 8 36 (-1) 2 (+1) 2 (+1) 0
Containers with scrolling 50 (+3) 49 (+1) 11 (-1) 11 (-1) 0
Widgets demo 68 40 15 15 0
All scenes avg. 25 37 6 6 0

Disclaimer: These benchmarks were run in an emulated environment using QEMU with instruction counting mode.
The timing values represent relative performance metrics within this specific virtualized setup and should
not be interpreted as absolute real-world performance measurements. Values are deterministic and useful for
comparing different LVGL features and configurations, but may not correlate directly with performance on
physical hardware. The measurements are intended for comparative analysis only.


🤖 This comment was automatically generated by a bot.

@catellie
Copy link
Copy Markdown
Author

@AndreCostaaa @FASTSHIFT - any chance to get this in? Preferably before the next bump of EspHome... 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v9.5.0 regression: lv_theme_default_init recurses infinitely via resolution_change_event_cb (from #9048) → task watchdog timeout on setup

1 participant