Update pixel buffer after changing matrix dimensions#5675
Conversation
WalkthroughThe PR refactors ChangesPixel Buffer Synchronization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)wled00/FX_fcn.cppIn file included from wled00/FX_fcn.cpp:12: ... [truncated 1074 characters] ... ins/clang/install/lib/clang/18/include" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
wled00/FX_fcn.cpp (2)
1285-1287: ⚡ Quick winAdd error handling for buffer allocation failure.
If
allocate_buffer()returns nullptr,_pixelswill be null and could cause issues beforeshow()catches it. Following the defensive pattern used inSegment::setGeometry()(lines 495-503), check allocation success immediately.🛡️ Proposed error handling
_pixels = static_cast<uint32_t*>(allocate_buffer(requiredMem, BFRALLOC_ENFORCE_PSRAM | BFRALLOC_NOBYTEACCESS | BFRALLOC_CLEAR)); + if (!_pixels) { + DEBUGFX_PRINTLN(F("!!! Not enough RAM for pixel buffer !!!")); + errorFlag = ERR_NORAM_PX; + } DEBUG_PRINTF_P(PSTR("strip buffer size: %uB\n"), requiredMem); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wled00/FX_fcn.cpp` around lines 1285 - 1287, The allocation result from allocate_buffer(requiredMem, BFRALLOC_ENFORCE_PSRAM | BFRALLOC_NOBYTEACCESS | BFRALLOC_CLEAR) assigned to _pixels must be checked for nullptr immediately (similar to Segment::setGeometry()); if it returns nullptr, log an error including requiredMem and a clear message via DEBUG_PRINTF_P or process logger, set a safe fallback state (e.g., leave _pixels null and set a flag or return/error out from the calling init function) to avoid dereferencing before show() is called, and ensure any subsequent code that assumes a valid buffer respects that flag or early-returns; update the allocation site where _pixels is assigned to perform this check and follow the same error-handling pattern used in Segment::setGeometry.
1281-1281: 💤 Low valueRemove commented dead code.
This commented-out line serves no purpose and should be deleted.
🧹 Proposed cleanup
void WS2812FX::updatePixelBuffer() { - //uint32_t currentMem = 0; uint32_t requiredMem = getLengthTotal() * sizeof(uint32_t);As per coding guidelines: "Remove dead/unused code — justify or delete it" and "Unused or dead code must be justified or removed to keep the codebase clean, maintainable, and readable".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wled00/FX_fcn.cpp` at line 1281, Remove the dead commented declaration "//uint32_t currentMem = 0;" from FX_fcn.cpp; delete the commented line referencing currentMem so the file no longer contains unused commented-out code (no other changes needed).Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@wled00/FX_fcn.cpp`:
- Around line 1284-1285: The comment is incorrect about enforcing PSRAM when
using BFRALLOC_NOBYTEACCESS; on classic ESP32 (CONFIG_IDF_TARGET_ESP32)
allocate_buffer() will take the heap_caps_malloc_prefer(... MALLOC_CAP_32BIT,
MALLOC_CAP_SPIRAM, MALLOC_CAP_8BIT ...) path when BFRALLOC_NOBYTEACCESS is set,
meaning PSRAM is only a fallback rather than guaranteed; update the inline
comment on the _pixels allocation (near allocate_buffer usage) to state that
32-bit/IRAM is preferred and PSRAM is used only if the preferred 32-bit
allocation isn’t available, or remove BFRALLOC_ENFORCE_PSRAM when also passing
BFRALLOC_NOBYTEACCESS for classic ESP32; reference allocate_buffer,
BFRALLOC_NOBYTEACCESS, BFRALLOC_ENFORCE_PSRAM, heap_caps_malloc_prefer and
p_malloc when making the change.
---
Nitpick comments:
In `@wled00/FX_fcn.cpp`:
- Around line 1285-1287: The allocation result from allocate_buffer(requiredMem,
BFRALLOC_ENFORCE_PSRAM | BFRALLOC_NOBYTEACCESS | BFRALLOC_CLEAR) assigned to
_pixels must be checked for nullptr immediately (similar to
Segment::setGeometry()); if it returns nullptr, log an error including
requiredMem and a clear message via DEBUG_PRINTF_P or process logger, set a safe
fallback state (e.g., leave _pixels null and set a flag or return/error out from
the calling init function) to avoid dereferencing before show() is called, and
ensure any subsequent code that assumes a valid buffer respects that flag or
early-returns; update the allocation site where _pixels is assigned to perform
this check and follow the same error-handling pattern used in
Segment::setGeometry.
- Line 1281: Remove the dead commented declaration "//uint32_t currentMem = 0;"
from FX_fcn.cpp; delete the commented line referencing currentMem so the file no
longer contains unused commented-out code (no other changes needed).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4a92b04a-4f6a-4abc-b8f5-2dcb908101f7
📒 Files selected for processing (2)
wled00/FX.hwled00/FX_fcn.cpp
Fix for #5669
Summary by CodeRabbit