Repository navigation
Closed
Milestone
Description
What happened?
When creating a 2D setup of say 32x32 with only 256 LEDs configured my C3 reliably crashes. I mentioned this before somewhere and also tried to fix it but it is still an issue.
Strangely it did work on an vanilla ESP32 when I tested. It also works fine if WLED is in off state.
To Reproduce Bug
set number of LEDs to 256, go to 2D setup and create a 32x32 matrix, no ledmap.json
Expected Behavior
handle it gracefully
Install Method
Self-Compiled
What version of WLED?
17.0
Which microcontroller/board are you seeing the problem on?
ESP32-C3
Relevant log/trace output
Crash report is totally incocnlusive...
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
Core 0 register dump:
MEPC : 0x40383ea0 RA : 0x40383e96 SP : 0x3fc9a270 GP : 0x3fc8d200
=> 0x40383ea0: shared_intr_isr at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_hw_support/intr_alloc.c:404
=> 0x40383e96: shared_intr_isr at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_hw_support/intr_alloc.c:403
TP : 0x3fc7c59c T0 : 0x4038806e T1 : 0x600c2140 T2 : 0x00000003
=> 0x4038806e: vPortEnterCritical at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port/riscv/port.c:246
S0/FP : 0x00ffaa00 S1 : 0x8000000b A0 : 0x00000003 A1 : 0x3fc99be4
A2 : 0x000000ff A3 : 0x00000004 A4 : 0x00000001 A5 : 0x3fc9e000
A6 : 0xfe010000 A7 : 0x00000000 S2 : 0x00001881 S3 : 0x00000001
S4 : 0x0000000f S5 : 0x000003dd S6 : 0x0000001d S7 : 0x3fca696c
S8 : 0x0000000f S9 : 0x3fc8ca2a S10 : 0x0000001d S11 : 0x00000000
T3 : 0x3fc9e068 T4 : 0x00000000 T5 : 0x00000001 T6 : 0x4201f2e6
=> 0x4201f2e6: _add(unsigned char, unsigned char) at wled00/FX_fcn.cpp:1338
MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000005 MTVAL : 0x00ffaa00
=> 0x40380001: _vector_table at ??:?
MHARTID : 0x00000000
Stack memory:
3fc9a270: 0x00001881 0x8000000b 0x3fca5054 0x4038b7be 0x00001881 0x8000000b 0x3fca5054 0x403801ee
=> 0x4038b7be: _global_interrupt_handler at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/riscv/interrupt.c:66
=> 0x403801ee: _interrupt_handler at ??:?Anything else?
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
softhack007 commentedon Jun 4, 2026
I've tried it on S3 - could not get a crash yet, but an intermediate "corrupted heap" appeared directly after saving the 2D setup
softhack007 commentedon Jun 4, 2026
getting closer - best debug attempt on -S3 yet, requires
-D WLED_USE_SHARED_RMT, so looks like something weird in going on with the Neopixelbus driver when creating the too-large 2D config 🤔 i can test with a -C3 devkit tomorrow.Stack Trace
EXCCAUSE
0x0000001d
Access to invalid address: STORE (wild pointer?)
softhack007 commentedon Jun 4, 2026
I know I shouldn't ask the rabbit, but I'm curious.....
@coderabbitai please analyze the source code related to the failure scenario described above: creating a 2D setup with matrix dimensions larger than the physical LED count. Look for evidence of heap corruption (overwriting not allocated memory with 0x0). Check the involved methods of NeoPixelBus for out-of-bounds parameters during 2D panel setup.
The final crash - at least on -S3 - seems to be a consequence of a corrupted heap. The
shared_intr_isrfunction might be involved, however its possibly not the root cause. The crash itself is only reproducible withWLED_USE_SHARED_RMT(-C3 only has this RMT driver), but my initial "CORRUPT HEAP" warning occurred with the non-shared NeoESP32RmtHI driver library.coderabbitai commentedon Jun 4, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 123148
🏁 Script executed:
Length of output: 195318
@softhack007I checked the 2D setup path, mapper, bus handoff, and the vendored NeoESP32RmtHI driver. My current read is:The likely heap corruption is in WLED’s global strip
_pixelsbuffer after 2D geometry changes, not in NeoPixelBus receiving out-of-bounds pixel indices.Why this matches the symptom
The 2D settings save path does this:
strip.suspend()strip.waitForIt()strip.deserializeMap()→ may callsetUpMatrix()strip.makeAutoSegments(true)strip.resume()from
wled00/set.cppLines 870-875.setUpMatrix()updatesSegment::maxWidth/Segment::maxHeightbased on the panel config atwled00/FX_2Dfcn.cppLines 24-35. For a too-large matrix,getLengthTotal()now effectively becomes the matrix virtual size, not just the physical LED count.The main segment is then recreated as the whole matrix:
wled00/FX_fcn.cppLines 1979-1982:_segments.emplace_back(0, Segment::maxWidth, 0, Segment::maxHeight);That segment’s own
pixelsbuffer is allocated fromlength() == width * height, so it looks OK.The suspicious part is the global
WS2812FX::_pixelsbuffer:finalizeInit()atwled00/FX_fcn.cppLine 1277 usinggetLengthTotal()._pixelsafter changingSegment::maxWidth/Segment::maxHeight.getLengthTotal():wled00/FX.hLine 898:if (n < getLengthTotal()) _pixels[n] = c;wled00/FX_fcn.cppLines 1733-1744: iteratesi < totalLenand reads_pixels[i].So if the device had, say, 256 physical LEDs and
_pixelswas allocated for 256, then saving a32x32matrix makesgetLengthTotal()become 1024. Any subsequent clear/blend/show path bounded by the newgetLengthTotal()can write/read beyond the old_pixelsallocation. If the overwrite color is black, that explains the heap head being overwritten with0x00000000.That lines up very well with:
NeoPixelBus / RMT parameter check
For the physical bus path, I don’t see strong evidence that NeoPixelBus itself is being called with out-of-bounds physical pixel indices from the normal show path:
BusDigitalcreates the NeoPixelBus object with physicalbc.countatwled00/bus_manager.cppLines 159-162.WS2812FX::show()maps logical/virtual pixels throughgetMappedPixelIndex(i)atwled00/FX_fcn.cppLine 1743.BusManager::setPixelColor()then filters withbus->containsPixel(pix)before callingbus->setPixelColor()atwled00/bus_manager.cppLines 1365-1369.So if
setUpMatrix()maps virtual matrix cells to physical indices beyond the actual strip length, those indices should simply miss all physical buses and not reachBusDigital::setPixelColor().There is still a minor cleanliness issue in
setUpMatrix():wled00/FX_2Dfcn.cppLines 99-113 incrementspixfor panel cells without clamping to_length.I’d consider changing that so entries beyond physical LEDs become
0xFFFF, but that alone won’t fix the heap corruption because the virtual matrix buffer still needs to be sized togetLengthTotal().About
shared_intr_isrThe shared RMT source was not present in the cloned tree, so I could only inspect the vendored high-priority RMT driver. In
lib/NeoESP32RmtHI/src/NeoEsp32RmtHIMethod.cpp, the ISR (NeoEsp32RmtMethodIsr) fills RMT memory from an already-established tx buffer and doesn’t allocate/free heap.Given the final crash lands in WiFi (
esf_buf_alloc/wDev_*), I’d treat the shared-RMT reproducibility as a timing/heap-layout amplifier, not the primary corruption source. The heap is probably already damaged by the resized 2D geometry before WiFi/RMT trips over it.Suggested fix direction
I’d add a dedicated resize/reset of
WS2812FX::_pixelswhenever 2D geometry changesgetLengthTotal()outsidefinalizeInit().Conceptually:
Then call it after
deserializeMap()/setUpMatrix()changes geometry and beforemakeAutoSegments(true)resumes normal rendering.Separately, I’d make
setUpMatrix()mark panel pixels beyond physical_lengthas missing:That would keep the virtual matrix valid for effects while preventing misleading physical mappings.
🐇🔎
🧠 Learnings used
softhack007 commentedon Jun 4, 2026
@coderabbitai could task concurrency be an amplifier for the problem? Is the async_tcp task only "catching" the 2D setup change (serialized later in main loop()), or is the async_tcp task already starting the geometry re-configuration itself? The blend/show path is only called from the main loop task.
Also consider that minimal crash scenario does not require de-serializing
ledmap.jsonor `2d-gaps.json´.softhack007 commentedon Jun 4, 2026
@DedeHai does this make sense to you?
coderabbitai commentedon Jun 4, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 118058
@softhack007Here's what the code shows:Q1: Task concurrency — amplifier or direct executor?
For
SUBPAGE_2D, the async_tcp task is the direct executor, not just a messenger:handleSettingsSet()forSUBPAGE_2D(set.cpp Lines 872–876) calls the full geometry reconfiguration synchronously on the async_tcp FreeRTOS task:By contrast, the LED settings path (
SUBPAGE_LEDS) correctly only sets a flag:doInitBusses = busesChanged; // set.cpp line 404…and defers
finalizeInit()toWLED::loop()(wled.cpp Lines 217–225). That path is safe.What does
suspend()/waitForIt()actually guard?_suspendisvolatile bool(FX.h Line 1019) andservice()checks it cooperatively at Lines 1290 and 1297. So:waitForIt()ensures the current in-flightservice()call has returned before modification starts — this part works.getLengthTotal(),customMappingTable, or iterates_segmentsis not blocked.waitForIt()returns and whilemakeAutoSegments(true)is rebuilding_segmentson Core 0, the main loop on Core 1 could be executing other code that touches the same objects.So yes, concurrency is a real amplifier — the cooperative
_suspendflag provides a soft synchronization window, not a hard lock. The comment in cfg.cpp Line 211 itself acknowledges the 2D setup path has had concurrency issues before:// cannot call strip.deserializeLedmap()/strip.setUpMatrix() here due to already locked JSON bufferQ2: Minimal crash path — no file I/O required
Confirmed. The crash needs only:
deserializeMap()called with noledmap.json→ immediately callssetUpMatrix()setUpMatrix()raisesSegment::maxWidth × maxHeightto the new matrix size (e.g., 32 × 32 = 1024)getLengthTotal()now returnsmaxWidth * maxHeight(FX_fcn.cpp Line 1871):unsigned len = Segment::maxWidth * Segment::maxHeight;_pixelswas allocated infinalizeInit()for the oldgetLengthTotal()(e.g., 256 LEDs × 4 bytes = 1 KB). There is no reallocation of_pixelsin the 2D save path — it only happens insidefinalizeInit().fill()call (FX.h Line 903:for (size_t i = 0; i < getLengthTotal(); i++) setPixelColor(i, c)) walks 1024 elements into a 256-element buffer → overwrites heap with0x00000000→CORRUPT HEAP: Expected 0xabba1234 got 0x00000000.No
ledmap.json, no2d-gaps.json, no gap table involved.Root cause in one sentence: The 2D save handler runs on the async_tcp task and changes
getLengthTotal()without reallocating_pixels— the first subsequentfill()/show()on the main loop then overflows the stale buffer. Thesuspend()/waitForIt()cooperative guard reduces the race window but cannot fully close it on a dual-core device, and it doesn't address the missing_pixelsresize at all.🐇🔍
🧠 Learnings used
softhack007 commentedon Jun 4, 2026
Side note: the race window also exists on single-core. We should look into replacing the wishful-thinking "
suspend()/waitForIt()cooperative guard" with a real mutex, or maybe with anatomicguard.willmmiles commentedon Jun 4, 2026
What we should do is handle web requests setting state synchronously in
loop(), and later isolate the render task. There are too many of these races to effectively handle them one at a time.If you're at the ready to sort out mutexes, #4808 is mostly there -- it still needs the JSON mutex backoff logic to be moved in to the handler queue, but the principle and architecture is there.
willmmiles commentedon Jun 5, 2026
(By 'isolate the render task' I mean pull all of the render state behind an object API and header breakup so we are guranteed there are no global variables that will influence the render task, and all external accesses go through an API where thread safety can be guaranteed.)
DedeHai commentedon Jun 5, 2026
I think this time it has nothing to do with async settings - the rabbit seems to be on to something. So if I understand it correctly the issue is the _pixels[] buffer: it gets allocated only in finalizeInit() which is only called when buses change or on bootup - since it requires the busconfigs to be filled.
If I switch the LEDs off, change the matrix to 32x32 it will save it. As soon as I now switch the LEDs to on, it crashes. The fix the rabbit suggests is probably valid - have a function to resize the _pixels[] buffer independently of finalizeInit().
Multiple fixes & new effect Flow 2D
Squashed commit of the following:
softhack007 commentedon Jun 12, 2026
@DedeHai @willmmiles is this a regression in 16.0.0 (compared to 0_15_x)?
If yes, then we should try to merge the fix soon so its part of 16.0.1 🤔
@netmindz
willmmiles commentedon Jun 12, 2026
@softhack007 0.15 didn't always require a global buffer, so probably only if that feature was enabled. Either way, I have no objections to backporting the fix for 16.0.1.
softhack007 commentedon Jun 16, 2026
solved with #5675