Skip to content

Commit

Permalink
effects bugfix: prevent crash when SEGLEN==1
Browse files Browse the repository at this point in the history
* Blurz and a few other effects would crash (or behave unexpectedly) for single pixel segments
  • Loading branch information
softhack007 committed Aug 5, 2023
1 parent 167a28b commit ed3bbc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed3bbc4

Please sign in to comment.