From c4f9629c130d507c9536d93467ee76eb5fa30539 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 23 Apr 2013 17:39:08 +0300 Subject: Fix crash when adding/removing points during animation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding/removing points during the animation of the previous add/remove operation resulted in a mismatch between visible point count and the actual point count, leading to crashes in code that assumed both to be the same. Added necessary safeguards and improved autotests to detect these cases. Task-number: QTRD-1984 Change-Id: I544d10a69e760a40d4c90a4f02de61d4d1bb974f Reviewed-by: Tomi Korpipää --- src/splinechart/splinechartitem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/splinechart/splinechartitem.cpp') diff --git a/src/splinechart/splinechartitem.cpp b/src/splinechart/splinechartitem.cpp index 4a46a724..4f1162c1 100644 --- a/src/splinechart/splinechartitem.cpp +++ b/src/splinechart/splinechartitem.cpp @@ -141,6 +141,9 @@ void SplineChartItem::updateGeometry() qreal rightMarginLine = centerPoint.x() + margin; qreal horizontal = centerPoint.y(); + // See ScatterChartItem::updateGeometry() for explanation why seriesLastIndex is needed + const int seriesLastIndex = m_series->count() - 1; + for (int i = 1; i < points.size(); i++) { // Interpolating spline fragments accurately is not trivial, and would anyway be ugly // when thick pen is used, so we work around it by utilizing three separate @@ -154,7 +157,7 @@ void SplineChartItem::updateGeometry() // degrees and both of the points are within the margin, one in the top half and one in the // bottom half of the chart, the bottom one gets clipped incorrectly. // However, this should be rare occurrence in any sensible chart. - currentSeriesPoint = m_series->pointAt(i); + currentSeriesPoint = m_series->pointAt(qMin(seriesLastIndex, i)); currentGeometryPoint = points.at(i); pointOffGrid = (currentSeriesPoint.x() < minX || currentSeriesPoint.x() > maxX); -- cgit v1.2.3