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.
This commit is contained in:
Ghostkeeper 2018-12-05 09:52:43 +01:00
parent a62da4e523
commit 5d95d11437
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276

View file

@ -42,8 +42,6 @@ Item
anchors.topMargin: UM.Theme.getSize("default_margin").height anchors.topMargin: UM.Theme.getSize("default_margin").height
visible: extrudersModel.count > 1 visible: extrudersModel.count > 1
currentIndex: Math.max(Cura.ExtruderManager.activeExtruderIndex, 0)
Repeater Repeater
{ {
id: 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. //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. //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. //Therefore we need to change it back to what it was: The active extruder index.