-
-
Couldn't load subscription status.
- Fork 3.8k
fix timing issue when changing 1D <-> 2D credits to @blazoncek #5023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce synchronization mechanisms to prevent race conditions during LED matrix geometry updates. Modified waitForIt timeout, added early-return guards to block segment mutations during active frame servicing, and wrapped geometry changes with suspend/waitForIt/resume sequences in configuration handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes The changes span three files with related but distinct synchronization modifications targeting race condition prevention. Logic density is moderate—understanding concurrency control, frame servicing state checks, and timeout behavior adjustments is required. Changes are somewhat heterogeneous, requiring separate reasoning for each file's modifications. Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
wled00/set.cpp (1)
818-824: Synchronization pattern correctly applied for matrix geometry changes.The suspend/waitForIt/resume sequence properly prevents effects from running during matrix reinitialization, aligning with the fix for issue #4911. The new code (lines 818-824) is correct.
The existing code at lines 911-913 uses only suspend/resume without waitForIt for single segment geometry changes. While this remains pre-existing code, applying the same waitForIt pattern to all geometry operations would improve consistency. However, this is an optional improvement since setGeometry calls affect individual segments rather than global matrix structure.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
wled00/FX_2Dfcn.cpp(2 hunks)wled00/FX_fcn.cpp(4 hunks)wled00/set.cpp(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
wled00/**/*.cpp
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use 2-space indentation for C++ source files (.cpp)
Files:
wled00/set.cppwled00/FX_fcn.cppwled00/FX_2Dfcn.cpp
🧠 Learnings (1)
📚 Learning: 2025-08-26T11:51:21.817Z
Learnt from: DedeHai
PR: wled/WLED#4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR #4798, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Applied to files:
wled00/FX_fcn.cppwled00/FX_2Dfcn.cpp
🧬 Code graph analysis (1)
wled00/FX_fcn.cpp (2)
usermods/Analog_Clock/Analog_Clock.cpp (1)
millis(151-155)usermods/word-clock-matrix/word-clock-matrix.cpp (1)
millis(294-321)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
- GitHub Check: wled_build / Build Environments (usermods)
- GitHub Check: wled_build / Build Environments (lolin_s2_mini)
- GitHub Check: wled_build / Build Environments (esp32_wrover)
- GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
- GitHub Check: wled_build / Build Environments (esp32c3dev)
- GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
- GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
- GitHub Check: wled_build / Build Environments (esp8266_2m_160)
- GitHub Check: wled_build / Build Environments (esp32_eth)
- GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
- GitHub Check: wled_build / Build Environments (esp32dev)
- GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
- GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
- GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
- GitHub Check: wled_build / Build Environments (nodemcuv2)
🔇 Additional comments (7)
wled00/FX_2Dfcn.cpp (2)
20-20: Clear warning about concurrency requirements.The WARNING comment appropriately documents that
setUpMatrix()must either be called from loop context or with explicit suspension, preventing misuse that could trigger the race condition addressed in #4911.
52-54: LGTM: Helpful documentation.The comment clarifies the relationship between panel layout dimensions and actual LED count, explaining the custom mapping and LED counting behavior.
wled00/FX_fcn.cpp (5)
1684-1691: Timeout increased to handle edge cases, but acknowledged as incomplete.Doubling the wait window from
1*getFrameTime()to2*getFrameTime()improves tolerance for slow effects at high FPS settings. However, the inline TODO referencing #4779 indicates this remains a partial fix rather than a complete solution to the timeout calculation.The expanded timeout reduces false-positive timeouts when effects exceed a single frame budget, which aligns with the broader race-condition fixes in this PR.
1817-1821: Defensive guard prevents mutations during servicing.The
isServicing()check provides defense-in-depth: even if a caller forgets tosuspend()/waitForIt()before invokingresetSegments(), this guard prevents segment corruption.
1828-1829: Guard in makeAutoSegments mirrors resetSegments pattern.Consistent with the guard added to
resetSegments()at line 1821, preventing segment mutation while the strip is actively rendering.
1900-1901: Guard in fixInvalidSegments completes the defensive trio.All three segment-mutation helpers (
resetSegments,makeAutoSegments,fixInvalidSegments) now reject calls during active servicing, preventing the race conditions reported in #4911 and #4800.
1964-1964: Warning documents suspension requirement for deserializeMap.Matches the warning added to
setUpMatrix()in FX_2Dfcn.cpp, line 20. Both functions modify strip geometry and require proper synchronization.
this fixes #4911 and #4800
Summary by CodeRabbit
Release Notes