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:
parent
406a254523
commit
7de7ef8e8c
@ -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.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.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._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
|
// 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.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.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._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;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -547,6 +547,7 @@ uint16_t Segment::virtualLength() const {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
uint16_t groupLen = groupLength();
|
uint16_t groupLen = groupLength();
|
||||||
|
if (groupLen < 1) groupLen = 1; // prevent division by zero - better safe than sorry ...
|
||||||
uint16_t vLength = (length() + groupLen - 1) / groupLen;
|
uint16_t vLength = (length() + groupLen - 1) / groupLen;
|
||||||
if (mirror) vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
if (mirror) vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||||
return vLength;
|
return vLength;
|
||||||
|
@ -34,7 +34,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
|
|
||||||
uint16_t start = elem["start"] | seg.start;
|
uint16_t start = elem["start"] | seg.start;
|
||||||
if (stop < 0) {
|
if (stop < 0) {
|
||||||
uint16_t len = elem["len"];
|
int len = elem["len"];
|
||||||
stop = (len > 0) ? start + len : seg.stop;
|
stop = (len > 0) ? start + len : seg.stop;
|
||||||
}
|
}
|
||||||
// 2D segments
|
// 2D segments
|
||||||
@ -473,7 +473,7 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
|
|||||||
root[F("stopY")] = seg.stopY;
|
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["grp"] = seg.grouping;
|
||||||
root[F("spc")] = seg.spacing;
|
root[F("spc")] = seg.spacing;
|
||||||
root[F("of")] = seg.offset;
|
root[F("of")] = seg.offset;
|
||||||
|
Loading…
Reference in New Issue
Block a user