fix some crashes when changing presets
This fixes some of the crashes I had when changing presets. still not a full solution ...
This commit is contained in:
		| @@ -90,7 +90,7 @@ Segment::Segment(const Segment &orig) { | ||||
|   if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); } | ||||
|   if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); } | ||||
|   if (orig._t)   { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); } | ||||
|   if (orig.leds && !Segment::_globalLeds) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); } | ||||
|   if (orig.leds && !Segment::_globalLeds && length() > 0) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); } | ||||
| } | ||||
|  | ||||
| // move constructor | ||||
| @@ -125,7 +125,7 @@ Segment& Segment::operator= (const Segment &orig) { | ||||
|     if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); } | ||||
|     if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); } | ||||
|     if (orig._t)   { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); } | ||||
|     if (orig.leds && !Segment::_globalLeds) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); } | ||||
|     if (orig.leds && !Segment::_globalLeds && length() > 0) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); } | ||||
|   } | ||||
|   return *this; | ||||
| } | ||||
| @@ -547,6 +547,7 @@ uint16_t Segment::virtualLength() const { | ||||
|   } | ||||
| #endif | ||||
|   uint16_t groupLen = groupLength(); | ||||
|   if (groupLen < 1) groupLen = 1;          // prevent division by zero - better safe than sorry ... | ||||
|   uint16_t vLength = (length() + groupLen - 1) / groupLen; | ||||
|   if (mirror) vLength = (vLength + 1) /2;  // divide by 2 if mirror, leave at least a single LED | ||||
|   return vLength; | ||||
|   | ||||
| @@ -34,7 +34,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"]; | ||||
|     stop = (len > 0) ? start + len : seg.stop; | ||||
|   } | ||||
|   // 2D segments | ||||
| @@ -473,7 +473,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; | ||||
|   root["grp"]    = seg.grouping; | ||||
|   root[F("spc")] = seg.spacing; | ||||
|   root[F("of")]  = seg.offset; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Frank
					Frank