From ed3bbc450998f5d85d7ea2d281211a484e3a5a71 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 6 Aug 2023 00:06:48 +0200 Subject: [PATCH] effects bugfix: prevent crash when SEGLEN==1 * Blurz and a few other effects would crash (or behave unexpectedly) for single pixel segments --- wled00/FX.cpp | 8 ++++---- wled00/wled.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index e918800284..d2ae06a43c 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2995,8 +2995,8 @@ uint16_t WS2812FX::candle(bool multi) if (multi) { //allocate segment data - uint16_t dataSize = (SEGLEN -1) *3; //max. 1365 pixels (ESP8266) - if (!SEGENV.allocateData(dataSize)) return candle(false); //allocation failed + uint16_t dataSize = max(1, SEGLEN -1) *3; //max. 1365 pixels (ESP8266) + if ((SEGLEN < 2) || (!SEGENV.allocateData(dataSize))) return candle(false); //allocation failed } //max. flicker range controlled by intensity @@ -3140,7 +3140,7 @@ uint16_t WS2812FX::mode_starburst_core(bool useAudio) { if ((doNewStar == true) && (stars[j].birth == 0)) { // Pick a random color and location. - uint16_t startPos = random16(SEGLEN-1); + uint16_t startPos = (SEGLEN > 1) ? random16(SEGLEN-1) : 0; float multiplier = (float)(random8())/255.0 * 1.0; stars[j].color = col_to_crgb(color_wheel(random8())); @@ -6343,7 +6343,7 @@ uint16_t WS2812FX::mode_blurz(void) { // Blurz. By Andrew Tul fade_out(SEGMENT.speed); uint16_t segLoc = random(SEGLEN); - leds[segmentToLogical(segLoc)] = color_blend(SEGCOLOR(1), color_from_palette(2*fftResult[SEGENV.aux0 % 16]*240/(SEGLEN-1), false, PALETTE_SOLID_WRAP, 0), 2*fftResult[SEGENV.aux0 % 16]); + leds[segmentToLogical(segLoc)] = color_blend(SEGCOLOR(1), color_from_palette((2*fftResult[SEGENV.aux0 % 16]*240)/max(1, SEGLEN-1), false, PALETTE_SOLID_WRAP, 0), 2*fftResult[SEGENV.aux0 % 16]); SEGENV.aux0++; SEGENV.aux0 = SEGENV.aux0 % 16; diff --git a/wled00/wled.h b/wled00/wled.h index cb48625c07..1d90600ef4 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2307251 // WLEDSR specific version +#define VERSION 2308061 // WLEDSR specific version #define SR_VERSION_NAME "0.13.4-beta" // WLEDSR version name --> some files need manual updating: package.json, package-lock.json, improv.cpp #define AC_VERSION 2208222 // AC WLED base version; last updated by PR #239 -> Merge AC-0.13.3 into dev