Panel_AMOLED: do not keep a framebuffer object whose init failed - #285
Merged
Merged
Conversation
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.
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Panel_AMOLED::initPanelFb()assigned_panel_fbbefore callinginit(). When the PSRAM frame buffer allocation failed, the object stayed behind without a buffer, so:initPanelFb()call returnedtrueimmediately without allocating anything, anddisplay()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 throwingnewthat fails would terminate instead of letting the caller fall back to direct drawing) and published to_panel_fbonly afterinit()succeeds; on any failure it is released and the method returnsfalseas 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.truewith a stale objecttrue, PSRAM usage unchanged (0 bytes)LoadProhibitedat address 0, reset loopfalse,getPanelFb()is nulltrue, 442372 bytes allocatedNormal boot with PSRAM available is unchanged. Fork CI green on this branch.