Skip to content

Commit

Permalink
Fixed liveview buffer over-write (fixes Aircoookie#2586 )
Browse files Browse the repository at this point in the history
(with odd LED counts > 256)
  • Loading branch information
Aircoookie committed Mar 18, 2022
1 parent eaa20ff commit 8601052
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions wled00/ws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ bool sendLiveLedsWs(uint32_t wsClient)

uint16_t used = strip.getLengthTotal();
uint16_t n = ((used -1)/MAX_LIVE_LEDS_WS) +1; //only serve every n'th LED if count over MAX_LIVE_LEDS_WS
AsyncWebSocketMessageBuffer * wsBuf = ws.makeBuffer(2 + (used*3)/n);
uint16_t bufSize = 2 + (used/n)*3;
AsyncWebSocketMessageBuffer * wsBuf = ws.makeBuffer(bufSize);
if (!wsBuf) return false; //out of memory
uint8_t* buffer = wsBuf->get();
buffer[0] = 'L';
buffer[1] = 1; //version

uint16_t pos = 2;
for (uint16_t i= 0; i < used; i += n)
for (uint16_t i= 0; pos < bufSize -3; i += n)
{
uint32_t c = strip.getPixelColor(i);
buffer[pos++] = qadd8(W(c), R(c)); //R, add white channel to RGB channels as a simple RGBW -> RGB map
Expand Down

0 comments on commit 8601052

Please sign in to comment.