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.
This commit is contained in:
Ghostkeeper 2020-04-23 11:38:27 +02:00
parent d9cdea9496
commit add9be387b
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -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)