From 0e5654e44b2e9ea1d827dea87248b140a987d7ad Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 17 Jan 2020 13:09:03 +0100 Subject: [PATCH] Guard against selection pass not existing yet It could happen that the selection pass is not initialised because you're right clicking on the screen before the first render has happened. Hopefully this fixes #6976. --- cura/CuraApplication.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f778cb0fab..221ccf9fb0 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import os @@ -1827,15 +1827,21 @@ class CuraApplication(QtApplication): def _onContextMenuRequested(self, x: float, y: float) -> None: # Ensure we select the object if we request a context menu over an object without having a selection. - if not Selection.hasSelection(): - node = self.getController().getScene().findObject(cast(SelectionPass, self.getRenderer().getRenderPass("selection")).getIdAtPosition(x, y)) - if node: - parent = node.getParent() - while(parent and parent.callDecoration("isGroup")): - node = parent - parent = node.getParent() + if Selection.hasSelection(): + return + selection_pass = cast(SelectionPass, self.getRenderer().getRenderPass("selection")) + if not selection_pass: # If you right-click before the rendering has been initialised there might not be a selection pass yet. + print("--------------ding! Got the crash.") + return + node = self.getController().getScene().findObject(selection_pass.getIdAtPosition(x, y)) + if not node: + return + parent = node.getParent() + while parent and parent.callDecoration("isGroup"): + node = parent + parent = node.getParent() - Selection.add(node) + Selection.add(node) @pyqtSlot() def showMoreInformationDialogForAnonymousDataCollection(self):