From 63649bb9a8e49677d0de7de261d3bb9c3b7e7a8b Mon Sep 17 00:00:00 2001 From: tetektoza Date: Wed, 20 Aug 2025 00:47:36 +0200 Subject: [PATCH] Assembly: Auto close on deleted doc for dialogs to avoid segfaults Currently if we close document on Assembly WB while having dialog opened, it will throw segfault because it is not being auto closed automatically during document close. This in turn resulted in dialog having dangling references to document that was no longer existing, throwing segfaults in random places. So solution is simple - add `setAutoCloseOnDeletedDocument` for every dialog in Assembly to avoid this situation and close every dialog upon document close. --- src/Mod/Assembly/CommandCreateBom.py | 5 ++++- src/Mod/Assembly/CommandCreateJoint.py | 1 + src/Mod/Assembly/CommandCreateSimulation.py | 10 ++++++++-- src/Mod/Assembly/CommandCreateView.py | 11 +++++++++-- src/Mod/Assembly/CommandInsertNewPart.py | 5 ++++- src/Mod/Assembly/JointObject.py | 1 + 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Mod/Assembly/CommandCreateBom.py b/src/Mod/Assembly/CommandCreateBom.py index d679f869eb..1220eea656 100644 --- a/src/Mod/Assembly/CommandCreateBom.py +++ b/src/Mod/Assembly/CommandCreateBom.py @@ -92,7 +92,10 @@ class CommandCreateBom: def Activated(self): self.panel = TaskAssemblyCreateBom() - Gui.Control.showDialog(self.panel) + dialog = Gui.Control.showDialog(self.panel) + if dialog is not None: + dialog.setAutoCloseOnDeletedDocument(True) + dialog.setDocumentName(App.ActiveDocument.Name) ######### Create Exploded View Task ########### diff --git a/src/Mod/Assembly/CommandCreateJoint.py b/src/Mod/Assembly/CommandCreateJoint.py index 57ddbfb863..81ac559255 100644 --- a/src/Mod/Assembly/CommandCreateJoint.py +++ b/src/Mod/Assembly/CommandCreateJoint.py @@ -60,6 +60,7 @@ def activateJoint(index): dialog = Gui.doCommandEval("dialog") if dialog is not None: dialog.setAutoCloseOnTransactionChange(True) + dialog.setAutoCloseOnDeletedDocument(True) dialog.setDocumentName(App.ActiveDocument.Name) diff --git a/src/Mod/Assembly/CommandCreateSimulation.py b/src/Mod/Assembly/CommandCreateSimulation.py index 2bf7c0f595..681cb6fb62 100644 --- a/src/Mod/Assembly/CommandCreateSimulation.py +++ b/src/Mod/Assembly/CommandCreateSimulation.py @@ -90,7 +90,10 @@ class CommandCreateSimulation: return self.panel = TaskAssemblyCreateSimulation() - Gui.Control.showDialog(self.panel) + dialog = Gui.Control.showDialog(self.panel) + if dialog is not None: + dialog.setAutoCloseOnDeletedDocument(True) + dialog.setDocumentName(App.ActiveDocument.Name) ######### Simulation Object ########### @@ -267,7 +270,10 @@ class ViewProviderSimulation: Gui.ActiveDocument.setEdit(assembly) panel = TaskAssemblyCreateSimulation(vpDoc.Object) - Gui.Control.showDialog(panel) + dialog = Gui.Control.showDialog(panel) + if dialog is not None: + dialog.setAutoCloseOnDeletedDocument(True) + dialog.setDocumentName(App.ActiveDocument.Name) return True diff --git a/src/Mod/Assembly/CommandCreateView.py b/src/Mod/Assembly/CommandCreateView.py index 3c8964d767..d25ff71141 100644 --- a/src/Mod/Assembly/CommandCreateView.py +++ b/src/Mod/Assembly/CommandCreateView.py @@ -76,7 +76,11 @@ class CommandCreateView: Gui.addModule("CommandCreateView") # NOLINT Gui.doCommand("panel = CommandCreateView.TaskAssemblyCreateView()") self.panel = Gui.doCommandEval("panel") - Gui.doCommandGui("Gui.Control.showDialog(panel)") + Gui.doCommandGui("dialog = Gui.Control.showDialog(panel)") + dialog = Gui.doCommandEval("dialog") + if dialog is not None: + dialog.setAutoCloseOnDeletedDocument(True) + dialog.setDocumentName(App.ActiveDocument.Name) ######### Exploded View Object ########### @@ -214,7 +218,10 @@ class ViewProviderExplodedView: Gui.ActiveDocument.setEdit(assembly) panel = TaskAssemblyCreateView(vobj.Object) - Gui.Control.showDialog(panel) + dialog = Gui.Control.showDialog(panel) + if dialog is not None: + dialog.setAutoCloseOnDeletedDocument(True) + dialog.setDocumentName(App.ActiveDocument.Name) return True diff --git a/src/Mod/Assembly/CommandInsertNewPart.py b/src/Mod/Assembly/CommandInsertNewPart.py index 55454a1fbc..f99fecda01 100644 --- a/src/Mod/Assembly/CommandInsertNewPart.py +++ b/src/Mod/Assembly/CommandInsertNewPart.py @@ -67,7 +67,10 @@ class CommandInsertNewPart: def Activated(self): panel = TaskAssemblyNewPart() - Gui.Control.showDialog(panel) + dialog = Gui.Control.showDialog(panel) + if dialog is not None: + dialog.setAutoCloseOnDeletedDocument(True) + dialog.setDocumentName(App.ActiveDocument.Name) class TaskAssemblyNewPart(JointObject.TaskAssemblyCreateJoint): diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 389d768d88..4cbf7628ba 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -1004,6 +1004,7 @@ class ViewProviderJoint: dialog = Gui.Control.showDialog(panel) if dialog is not None: dialog.setAutoCloseOnTransactionChange(True) + dialog.setAutoCloseOnDeletedDocument(True) dialog.setDocumentName(App.ActiveDocument.Name) return True