From 2f1c1575479df5b4cca67c01456af230594e8ba5 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 23 Nov 2021 17:54:26 +0100 Subject: [PATCH] Don't attempt writing a workspace before there is a global stack This is normally not possible from the interface. However on MacOS, the application menu gets carried to the top bar of the operating system. It is not blocked there, and the user could write a project file before they even add a printer. This prevents Cura from crashing when they do that. Fixes Sentry issue CURA-2ZR. --- plugins/3MFWriter/ThreeMFWorkspaceWriter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py index 9f4ab8e5fa..7f39d300b7 100644 --- a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py +++ b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py @@ -32,6 +32,12 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): Logger.error("3MF Writer class is unavailable. Can't write workspace.") return False + global_stack = machine_manager.activeMachine + if global_stack is None: + self.setInformation(catalog.i18nc("@error", "There is no workspace yet to write. Please add a printer first.")) + Logger.error("Tried to write a 3MF workspace before there was a global stack.") + return False + # Indicate that the 3mf mesh writer should not close the archive just yet (we still need to add stuff to it). mesh_writer.setStoreArchive(True) mesh_writer.write(stream, nodes, mode) @@ -40,7 +46,6 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): if archive is None: # This happens if there was no mesh data to write. archive = zipfile.ZipFile(stream, "w", compression = zipfile.ZIP_DEFLATED) - global_stack = machine_manager.activeMachine try: # Add global container stack data to the archive.