Fix crash when adding a machine without materials

CURA-6775
This commit is contained in:
Jaime van Kessel 2019-09-19 15:12:29 +02:00
parent 2b4144386f
commit 830b22e381
No known key found for this signature in database
GPG key ID: 3710727397403C91

View file

@ -27,6 +27,9 @@ class BaseMaterialsModel(ListModel):
self._application = CuraApplication.getInstance() self._application = CuraApplication.getInstance()
self._available_materials = {} # type: Dict[str, MaterialNode]
self._favorite_ids = set() # type: Set[str]
# Make these managers available to all material models # Make these managers available to all material models
self._container_registry = self._application.getInstance().getContainerRegistry() self._container_registry = self._application.getInstance().getContainerRegistry()
self._machine_manager = self._application.getMachineManager() self._machine_manager = self._application.getMachineManager()
@ -60,9 +63,6 @@ class BaseMaterialsModel(ListModel):
self.addRoleName(Qt.UserRole + 15, "container_node") self.addRoleName(Qt.UserRole + 15, "container_node")
self.addRoleName(Qt.UserRole + 16, "is_favorite") self.addRoleName(Qt.UserRole + 16, "is_favorite")
self._available_materials = None # type: Optional[Dict[str, MaterialNode]]
self._favorite_ids = set() # type: Set[str]
def _updateExtruderStack(self): def _updateExtruderStack(self):
global_stack = self._machine_manager.activeMachine global_stack = self._machine_manager.activeMachine
if global_stack is None: if global_stack is None:
@ -122,6 +122,8 @@ class BaseMaterialsModel(ListModel):
# Update the available materials (ContainerNode) for the current active machine and extruder setup. # Update the available materials (ContainerNode) for the current active machine and extruder setup.
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
if not global_stack.hasMaterials:
return # There are no materials for this machine, so nothing to do.
extruder_stack = global_stack.extruders.get(str(self._extruder_position)) extruder_stack = global_stack.extruders.get(str(self._extruder_position))
if not extruder_stack: if not extruder_stack:
return return