mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-04 04:23:58 -06:00
Prevent crash when material is unknown
Fixes CURA-GV
This commit is contained in:
parent
0029221fd5
commit
dd359da1cf
1 changed files with 11 additions and 6 deletions
|
@ -369,7 +369,8 @@ class MachineManager(QObject):
|
|||
material_node = variant_node.materials.get(extruder.material.getMetaDataEntry("base_file"))
|
||||
if material_node is None:
|
||||
Logger.log("w", "An extruder has an unknown material, switching it to the preferred material")
|
||||
self.setMaterialById(extruder.getMetaDataEntry("position"), machine_node.preferred_material)
|
||||
if not self.setMaterialById(extruder.getMetaDataEntry("position"), machine_node.preferred_material):
|
||||
Logger.log("w", "Failed to switch to %s keeping old material instead", machine_node.preferred_material)
|
||||
|
||||
|
||||
@staticmethod
|
||||
|
@ -1452,17 +1453,21 @@ class MachineManager(QObject):
|
|||
self.updateMaterialWithVariant(None) # Update all materials
|
||||
self._updateQualityWithMaterial()
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def setMaterialById(self, position: str, root_material_id: str) -> None:
|
||||
@pyqtSlot(str, str, result = bool)
|
||||
def setMaterialById(self, position: str, root_material_id: str) -> bool:
|
||||
if self._global_container_stack is None:
|
||||
return
|
||||
return False
|
||||
|
||||
machine_definition_id = self._global_container_stack.definition.id
|
||||
position = str(position)
|
||||
extruder_stack = self._global_container_stack.extruderList[int(position)]
|
||||
nozzle_name = extruder_stack.variant.getName()
|
||||
material_node = ContainerTree.getInstance().machines[machine_definition_id].variants[nozzle_name].materials[root_material_id]
|
||||
self.setMaterial(position, material_node)
|
||||
|
||||
materials = ContainerTree.getInstance().machines[machine_definition_id].variants[nozzle_name].materials
|
||||
if root_material_id in materials:
|
||||
self.setMaterial(position, materials[root_material_id])
|
||||
return True
|
||||
return False
|
||||
|
||||
@pyqtSlot(str, "QVariant")
|
||||
def setMaterial(self, position: str, container_node, global_stack: Optional["GlobalStack"] = None) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue