Skip to content

fix: guard against null DMA buffer in Panel_AMOLED_Framebuffer::display()#211

Merged
lovyan03 merged 6 commits into
m5stack:developfrom
inanimate-tech:fix/amoled-dma-null-guard
Jul 7, 2026
Merged

fix: guard against null DMA buffer in Panel_AMOLED_Framebuffer::display()#211
lovyan03 merged 6 commits into
m5stack:developfrom
inanimate-tech:fix/amoled-dma-null-guard

Conversation

@ACEFGI

@ACEFGI ACEFGI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Panel_AMOLED_Framebuffer::display() obtains two per-line DMA buffers from getDMABuffer() and memcpys framebuffer data into them each line, but only null-checks _frame_buffer — not the DMA buffers. When the DMA-capable internal heap is exhausted (transient memory pressure), getDMABuffer() returns nullptr, so the flush memcpys into a null pointer and the device panics (StoreProhibited, write to 0x00000000).

Fix

Skip the flush if either DMA buffer is null, leaving the dirty rectangle (_range_mod) intact so the next display() retries once memory frees. A per-instance flag edge-logs the condition (ESP_LOGW) and its recovery (ESP_LOGI) without per-frame spam.

Minimal repro

  1. Occupy DMA-capable internal RAM until heap_caps_get_largest_free_block(MALLOC_CAP_DMA) is below one display line's bytes (panel_width * bytes_per_pixel).
  2. Do a full-screen draw + flush on an AMOLED framebuffer panel.

Without this patch it panics on the null memcpy; with it the frame is skipped and redraws once memory is freed.

Notes

The same unchecked getDMABuffer() pattern also appears in the writeImage* pixel-copy paths; this PR scopes to the framebuffer flush we could reproduce and verify — glad to extend it to a full sweep if you'd prefer.

Disclosure on process: this patch was authored by an AI coding agent and reviewed by a human; the bug was discovered and the fix validated on hardware through human + agent collaboration (fault-injection confirming the null path panics without the guard and is safely skipped with it). Happy to open a tracking issue first if that's your preference.

RikerZhu and others added 6 commits April 29, 2026 16:16
The previous change to namespace alias broke direct font calls in user scripts. Reverting to ensure users don't need to manually update their font references.
Panel_AMOLED_Framebuffer::display() guards a null _frame_buffer but not
the per-line DMA buffers from getDMABuffer(), which return nullptr when
the DMA-capable internal heap is transiently exhausted. The subsequent
memcpy into a null pointer faults (StoreProhibited). Skip the flush and
leave the dirty range intact so the next display() retries once memory
frees. A new per-instance _dma_oom flag edge-logs the condition
(ESP_LOGW) and its recovery (ESP_LOGI) without per-frame spam.

Reproduced and fixed on an M5Stack StopWatch (466x466 CO5300): under
memory pressure the small per-line alloc fails while a full-screen buffer
is cached, and any transient (e.g. a TLS reconnect) tips it over.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lovyan03 lovyan03 changed the base branch from master to develop July 7, 2026 01:49
@lovyan03 lovyan03 merged commit bde4f49 into m5stack:develop Jul 7, 2026
22 checks passed
@lovyan03

lovyan03 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Hello, @ACEFGI
Thank you for your contribution.
This PR will be included in the next update release.

lovyan03 pushed a commit to lovyan03/LovyanGFX that referenced this pull request Jul 7, 2026
Panel_AMOLED_Framebuffer::display() guards a null _frame_buffer but not
the per-line DMA buffers from getDMABuffer(), which return nullptr when
the DMA-capable internal heap is transiently exhausted. The subsequent
memcpy into a null pointer faults (StoreProhibited). Skip the flush and
leave the dirty range intact so the next display() retries once memory
frees. A new per-instance _dma_oom flag edge-logs the condition
(ESP_LOGW) and its recovery (ESP_LOGI) without per-frame spam.

Ported from m5stack/M5GFX#211, originally authored by Zac Anderson.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
lovyan03 pushed a commit that referenced this pull request Jul 7, 2026
Follow-up to #211: apply the same null guard to the three
getDMABuffer() call sites in writeImage(), via a shared
get_dma_buffer_checked() helper with edge-triggered logging.
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.

3 participants