mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-11 11:28:58 +08:00
Prevent crash when material is unknown
Fixes CURA-GV
This commit is contained in:
parent
0029221fd5
commit
dd359da1cf
@ -369,7 +369,8 @@ class MachineManager(QObject):
|
|||||||
material_node = variant_node.materials.get(extruder.material.getMetaDataEntry("base_file"))
|
material_node = variant_node.materials.get(extruder.material.getMetaDataEntry("base_file"))
|
||||||
if material_node is None:
|
if material_node is None:
|
||||||
Logger.log("w", "An extruder has an unknown material, switching it to the preferred material")
|
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
|
@staticmethod
|
||||||
@ -1452,17 +1453,21 @@ class MachineManager(QObject):
|
|||||||
self.updateMaterialWithVariant(None) # Update all materials
|
self.updateMaterialWithVariant(None) # Update all materials
|
||||||
self._updateQualityWithMaterial()
|
self._updateQualityWithMaterial()
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str, result = bool)
|
||||||
def setMaterialById(self, position: str, root_material_id: str) -> None:
|
def setMaterialById(self, position: str, root_material_id: str) -> bool:
|
||||||
if self._global_container_stack is None:
|
if self._global_container_stack is None:
|
||||||
return
|
return False
|
||||||
|
|
||||||
machine_definition_id = self._global_container_stack.definition.id
|
machine_definition_id = self._global_container_stack.definition.id
|
||||||
position = str(position)
|
position = str(position)
|
||||||
extruder_stack = self._global_container_stack.extruderList[int(position)]
|
extruder_stack = self._global_container_stack.extruderList[int(position)]
|
||||||
nozzle_name = extruder_stack.variant.getName()
|
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")
|
@pyqtSlot(str, "QVariant")
|
||||||
def setMaterial(self, position: str, container_node, global_stack: Optional["GlobalStack"] = None) -> None:
|
def setMaterial(self, position: str, container_node, global_stack: Optional["GlobalStack"] = None) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user