From 5d95d1143762a72e7cfe9c384c9d5752f6b888c2 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 5 Dec 2018 09:52:43 +0100 Subject: [PATCH] Use setCurrentIndex to switch tabs at activeExtruderChanged This fixes a mysterious segfault. We still don't know why the segfault occurred though. All we know is that QML logs something about a binding loop on currentIndex, and Qt logs something about removing range [-1 through 0] from VisualItemModel. When the tab bar is then made visible, Cura crashes. It is a nondeterministic crash. After this change, we are not seeing it any more (but with any nondeterministic bug, it's hard to verify that it was actually fixed). Contributes to issue CURA-5876. --- .../ConfigurationMenu/CustomConfiguration.qml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml b/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml index 2667c837ba..18c2dabb0f 100644 --- a/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml +++ b/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml @@ -42,8 +42,6 @@ Item anchors.topMargin: UM.Theme.getSize("default_margin").height visible: extrudersModel.count > 1 - currentIndex: Math.max(Cura.ExtruderManager.activeExtruderIndex, 0) - Repeater { id: repeater @@ -68,6 +66,18 @@ Item } } + //When active extruder changes for some other reason, switch tabs. + //Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex! + //This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead. + Connections + { + target: Cura.ExtruderManager + onActiveExtruderChanged: + { + tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex); + } + } + //When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt. //This causes the currentIndex of the tab to be in an invalid position which resets it to 0. //Therefore we need to change it back to what it was: The active extruder index.