From d9cdea9496f340095861eb406e33f9442a53a2d2 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Apr 2020 11:08:32 +0200 Subject: [PATCH 1/2] Don't crash when material file is missing This could happen because a material is deleted right at that moment, since the SendMaterialJob is done on a separate thread. Fixes Sentry issue CURA-JZ. --- .../UM3NetworkPrinting/src/Network/SendMaterialJob.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py b/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py index 5abc3cfde4..49e088100d 100644 --- a/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py +++ b/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py @@ -92,9 +92,13 @@ class SendMaterialJob(Job): parts = [] # Add the material file. - with open(file_path, "rb") as f: - parts.append(self.device.createFormPart("name=\"file\"; filename=\"{file_name}\"" - .format(file_name = file_name), f.read())) + try: + with open(file_path, "rb") as f: + parts.append(self.device.createFormPart("name=\"file\"; filename=\"{file_name}\"" + .format(file_name = file_name), f.read())) + except FileNotFoundError: + Logger.error("Unable to send material {material_id}, since it has been deleted in the meanwhile.".format(material_id = material_id)) + return # Add the material signature file if needed. signature_file_path = "{}.sig".format(file_path) From add9be387ba27fab3f5b23effc29b6ccd2158e55 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Apr 2020 11:38:27 +0200 Subject: [PATCH 2/2] Fix crash when creating a socket before the plug-in is fully registered The plug-in ID is set once the register function is completed, so after initialisation. If the _createSocket function is called in between, Cura would crash. I don't know why the _createSocket function would be called in between, but possibly another plug-in causes an event that calls it since it's being called on many events (everything that would initiate a reslice). Fixes Sentry issue CURA-K4. --- plugins/CuraEngineBackend/CuraEngineBackend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 3dd0589865..6a8a4a7347 100755 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -720,9 +720,12 @@ class CuraEngineBackend(QObject, Backend): ## Creates a new socket connection. def _createSocket(self, protocol_file: str = None) -> None: if not protocol_file: + if not self.getPluginId(): + Logger.error("Can't create socket before CuraEngineBackend plug-in is registered.") + return plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId()) if not plugin_path: - Logger.log("e", "Could not get plugin path!", self.getPluginId()) + Logger.error("Could not get plugin path!", self.getPluginId()) return protocol_file = os.path.abspath(os.path.join(plugin_path, "Cura.proto")) super()._createSocket(protocol_file)