Skip to content

Panel_AMOLED: do not keep a framebuffer object whose init failed - #285

Merged
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:amoled_fb_init_failure
Sep 11, 2026
Merged

lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:amoled_fb_init_failure

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Summary

Panel_AMOLED::initPanelFb() assigned _panel_fb before calling init(). When the PSRAM frame buffer allocation failed, the object stayed behind without a buffer, so:

  • the next initPanelFb() call returned true immediately without allocating anything, and
  • display() was routed through a frame buffer that does not exist.

A caller that adopts that panel after the "successful" retry (the CO5300-based board setup does exactly this) dereferences a null line buffer. The object is now created locally with std::nothrow (exceptions are disabled on the ESP32 targets, so a throwing new that fails would terminate instead of letting the caller fall back to direct drawing) and published to _panel_fb only after init() succeeds; on any failure it is released and the method returns false as documented.

Verified

Test firmware on an ESP32-S3 board with a 468x468 CO5300 panel: exhaust PSRAM before init so the frame buffer allocation fails, free it, then call initPanelFb() again and adopt the returned panel.

first call (no PSRAM) retry after freeing PSRAM drawing through the adopted panel
before returns true with a stale object returns true, PSRAM usage unchanged (0 bytes) LoadProhibited at address 0, reset loop
after returns false, getPanelFb() is null returns true, 442372 bytes allocated works, no reset

Normal boot with PSRAM available is unchanged. Fork CI green on this branch.

initPanelFb() assigned _panel_fb before init(), so when the PSRAM
allocation failed the object stayed behind without a buffer. The next
call then returned true immediately and display() was routed through
a framebuffer that does not exist; a caller that adopts that panel
(as the CO5300 board setup does) dereferences a null line buffer.

Create the object locally with std::nothrow (exceptions are disabled
on the ESP32 targets, so a throwing new that fails would terminate
instead of letting the caller fall back to direct drawing), and
publish it to _panel_fb only after init() succeeds. On any failure
the object is released and the method returns false as documented.
@lovyan03
lovyan03 merged commit 652e2d3 into m5stack:develop Sep 11, 2026
27 checks passed
@ainyan03
ainyan03 deleted the amoled_fb_init_failure branch September 11, 2026 08:51
@ainyan03 ainyan03 mentioned this pull request Sep 14, 2026
@lovyan03 lovyan03 mentioned this pull request Sep 14, 2026
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.

2 participants