diff --git a/wled00/FX.h b/wled00/FX.h index e12b03c3..3d285296 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -540,7 +540,7 @@ typedef struct Segment { inline uint16_t width(void) const { return (stop > start) ? (stop - start) : 0; } // segment width in physical pixels (length if 1D) inline uint16_t height(void) const { return (stopY > startY) ? (stopY - startY) : 0; } // segment height (if 2D) in physical pixels // WLEDMM make sure its always > 0 inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels - inline uint16_t groupLength(void) const { return grouping + spacing; } + inline uint16_t groupLength(void) const { return max(1, grouping + spacing); } // WLEDMM length = 0 could lead to div/0 in virtualWidth() and virtualHeight() inline uint8_t getLightCapabilities(void) const { return _capabilities; } static size_t getUsedSegmentData(void) { return _usedSegmentData; } // WLEDMM size_t @@ -628,6 +628,7 @@ typedef struct Segment { inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed uint_fast16_t width = virtualWidth(); // segment width in logical pixels uint_fast16_t height = virtualHeight(); // segment height in logical pixels + if ((width == 0) || (height == 0)) return 0; // softhack007 avoid div/0 return (x%width) + (y%height) * width; } void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 636ed4f7..57f3604e 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -115,7 +115,7 @@ void WS2812FX::setUpMatrix() { // 1 ... active pixel (it will count and will be mapped) JsonArray map = doc.as(); gapSize = map.size(); - if (!map.isNull() && gapSize >= customMappingSize) { // not an empty map + if (!map.isNull() && (gapSize > 0) && gapSize >= customMappingSize) { // not an empty map //softhack also check gapSize>0 gapTable = new int8_t[gapSize]; if (gapTable) for (size_t i = 0; i < gapSize; i++) { gapTable[i] = constrain(map[i], -1, 1); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 769ef356..fea1364d 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1050,7 +1050,7 @@ uint32_t Segment::getPixelColor(int i) i += start; /* offset/phase */ i += offset; - if (i >= stop) i -= length(); + if ((i >= stop) && (stop>0)) i -= length(); // WLEDMM avoid negative index (stop = 0 is a possible value) return strip.getPixelColor(i); } diff --git a/wled00/json.cpp b/wled00/json.cpp index ecb82442..e91b2f3a 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -100,7 +100,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId) uint16_t start = elem["start"] | seg.start; if (stop < 0) { - uint16_t len = elem["len"]; + int len = elem["len"]; // WLEDMM bugfix for broken presets with len < 0 stop = (len > 0) ? start + len : seg.stop; } // 2D segments @@ -113,7 +113,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId) elem.remove("id"); // remove for recursive call elem.remove("rpt"); // remove for recursive call elem.remove("n"); // remove for recursive call - uint16_t len = stop - start; + uint16_t len = (stop >= start) ? (stop - start) : 0; // WLEDMM stop < 1 is allowed, so we need to avoid underflow for (size_t i=id+1; i= strip.getLengthTotal()) break; @@ -592,7 +592,7 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b root[F("stopY")] = seg.stopY; } } - if (!forPreset) root["len"] = seg.stop - seg.start; + if (!forPreset) root["len"] = (seg.stop >= seg.start) ? (seg.stop - seg.start) : 0; // WLEDMM correct handling for stop=0 root["grp"] = seg.grouping; root[F("spc")] = seg.spacing; root[F("of")] = seg.offset; diff --git a/wled00/wled.h b/wled00/wled.h index 0a0402d9..e95c82de 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2306210 +#define VERSION 2306211 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG