From 02f41bbe60ccc8bd3f9dd35531413bc5078147e7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 20 Dec 2024 22:18:10 +0100 Subject: [PATCH] App: Fix possible crash when postponing the destruction of a removed property Fixes #18601 --- src/App/Property.cpp | 1 + src/Mod/Test/Document.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/App/Property.cpp b/src/App/Property.cpp index 2b20f8f166..904d91f8ce 100644 --- a/src/App/Property.cpp +++ b/src/App/Property.cpp @@ -213,6 +213,7 @@ struct PropertyCleaner auto p = _RemovedProps.back(); _RemovedProps.pop_back(); if (p != prop) { + p->setContainer(nullptr); delete p; } else { diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index e59ab99e78..4959650789 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -44,6 +44,16 @@ class Proxy: self.Dictionary = data +class MyFeature: + def __init__(self, obj): + obj.Proxy = self + obj.addProperty("App::PropertyLinkList", "propLink") + + def onDocumentRestored(self, obj): + if hasattr(obj, "propLink"): + obj.removeProperty("propLink") + + class DocumentBasicCases(unittest.TestCase): def setUp(self): self.Doc = FreeCAD.newDocument("CreateTest") @@ -56,6 +66,15 @@ class DocumentBasicCases(unittest.TestCase): self.Doc = FreeCAD.open(SaveName) return self.Doc + def testIssue18601(self): + lnk = self.Doc.addObject("App::FeaturePython", "MyLink") + obj = self.Doc.addObject("App::FeaturePython", "MyFeature") + fea = MyFeature(obj) + obj.propLink = [lnk] + doc = self.saveAndRestore() + FreeCAD.closeDocument(doc.Name) + self.Doc = FreeCAD.newDocument("CreateTest") + def testAccessByNameOrID(self): obj = self.Doc.addObject("App::DocumentObject", "MyName")