From 10e318033274add00613edb730bf0d065fe4e1c5 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 13 Aug 2019 12:58:04 +0200 Subject: [PATCH] #4565 Highlight Curves : Clicking on curve causes access violation Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list plotCurve->setZ() causes the ordering of items in the list to change --- ApplicationCode/UserInterface/RiuQwtPlot.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuQwtPlot.cpp b/ApplicationCode/UserInterface/RiuQwtPlot.cpp index c8ccef6f6c..bebfbeeeae 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlot.cpp @@ -244,7 +244,10 @@ void RiuQwtPlot::selectClosestCurve(const QPoint& pos) //-------------------------------------------------------------------------------------------------- void RiuQwtPlot::highlightCurve(const QwtPlotCurve* closestCurve) { - for (QwtPlotItem* plotItem : this->itemList()) + // NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list + // plotCurve->setZ() causes the ordering of items in the list to change + auto plotItemList = this->itemList(); + for (QwtPlotItem* plotItem : plotItemList) { QwtPlotCurve* plotCurve = dynamic_cast(plotItem); if (plotCurve) @@ -293,7 +296,10 @@ void RiuQwtPlot::highlightCurve(const QwtPlotCurve* closestCurve) //-------------------------------------------------------------------------------------------------- void RiuQwtPlot::resetCurveHighlighting() { - for (QwtPlotItem* plotItem : this->itemList()) + // NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list + // plotCurve->setZ() causes the ordering of items in the list to change + auto plotItemList = this->itemList(); + for (QwtPlotItem* plotItem : plotItemList) { QwtPlotCurve* plotCurve = dynamic_cast(plotItem); if (plotCurve && m_originalCurveColors.count(plotCurve))