Conversation
- Add bounds checking for loopIndex to prevent array bounds violation - Reset loopIndex to 0 when it reaches BACKLIGHT_NUM_LEDS - Prevents ESP8266 crash when loop effect completes one cycle - Fixes issue where first LED would stay lit and device would crash The loop effect now safely cycles through all backlight LEDs continuously without memory violations.
|
appreciate the work though in fixing something i never tested (i got lazy) |
Using winston's suggestion Co-authored-by: Winston Lu <33874247+Winston-Lu@users.noreply.github.com>
|
could you also confirm that the changes work? Gave my own shelf away since i was moving to a different country so I dont have a means of testing it myself anymore |
|
Haha i got the feeling that this was untested already. I might refracture/update it tonight because there are some more things broken. (like the brightness control not working at all). I'd like to add some functions like a countdown clock or something but i'm right at the edge of IRAM. I'm thinking of moving the grid to progmem, might be slower but i'm wondering what the actual difference will be. |
Will let you know later tonight |
|
feel free to try whatever, this project was done in my early days of C++ before i had any of my code reviewed before, but likely a lot of memory is being taken up by the arrays of the RGB pixels. We should still have enough budget to calculate things on runtime if needed, the worst one for runtime is the gradient since I calculate each pixel every time instead of caching or saving results, but the rest should run at 30+fps |
Problem
The backlight loop effect (case 255) was causing ESP8266 crashes after completing one full cycle. The issue occurred because:
loopIndexvariable incremented indefinitely without bounds checkingloopIndexexceededBACKLIGHT_NUM_LEDS, it caused array bounds violationSolution
Added bounds checking and proper loop reset:
if (loopIndex >= BACKLIGHT_NUM_LEDS)loopIndexto 0 when it reaches the end of the LED arrayChanges
Backlight.cpp: Added bounds checking in the loop effect (case 255)Testing