From c592b7a7fdfe925266b7ab4547b185ea60cb843a Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 9 Feb 2021 21:05:32 +0100 Subject: [PATCH] Fix crash When use the function "invert selection" qet crash when a selected conductor is being deselected. --- sources/diagram.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 40bdffe9c..857aab312 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1693,10 +1693,26 @@ void Diagram::invertSelection() if (items().isEmpty()) return; blockSignals(true); - foreach (QGraphicsItem *item, - items()) item -> setSelected(!item -> isSelected()); + + //Get only allowed graphics item + //because some item can be deleted between the + //call of items() and the use of the item in the second 'for' loop + //and crash Qet with a segfault. + QVector item_list; + for (auto item : items()) + { + if (dynamic_cast(item) || + dynamic_cast(item) || + dynamic_cast(item)) { + item_list << item; + } + } + for (auto item : qAsConst(item_list)) { + item -> setSelected(!item -> isSelected()); + } + blockSignals(false); - emit(selectionChanged()); + emit selectionChanged(); } /**