From 10d2fe443143ca2d4ec00fcf404824b4a8ec6bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 29 Oct 2019 09:10:32 +0100 Subject: [PATCH] Fixed crash on empty segment Fixes #239 --- src/data/track.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/data/track.cpp b/src/data/track.cpp index 7c9a533c..e4a30c80 100644 --- a/src/data/track.cpp +++ b/src/data/track.cpp @@ -74,17 +74,19 @@ Track::Track(const TrackData &data) : _data(data), _pause(0) for (int i = 0; i < _data.size(); i++) { const SegmentData &sd = _data.at(i); + _segments.append(Segment()); if (sd.isEmpty()) continue; // precompute distances, times, speeds and acceleration QVector acceleration; - _segments.append(Segment()); Segment &seg = _segments.last(); - seg.distance.append(i ? _segments.at(i-1).distance.last() : 0); - seg.time.append(i ? _segments.at(i-1).time.last() : + seg.distance.append(i && !_segments.at(i-1).distance.isEmpty() + ? _segments.at(i-1).distance.last() : 0); + seg.time.append(i && !_segments.at(i-1).time.isEmpty() + ? _segments.at(i-1).time.last() : sd.first().hasTimestamp() ? 0 : NAN); seg.speed.append(sd.first().hasTimestamp() ? 0 : NAN); acceleration.append(sd.first().hasTimestamp() ? 0 : NAN);