From 93ee3a34759c88c96760be74fccfb1f9cebba15c Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 12 Mar 2025 11:43:47 +0100 Subject: [PATCH] App: Remove assert() from PropertyXLink::Restore If the property is added to a view provider then in debug mode this will cause a crash while in release mode this will cause undefined behaviour because of a static_cast. To fix crashes remove the assert() and replace the static_cast with freecad_cast. --- src/App/PropertyLinks.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 3d090cc384..f7d65a4187 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -4281,14 +4281,12 @@ void PropertyXLink::Restore(Base::XMLReader& reader) name = reader.getAttribute("name"); } - assert(getContainer()->isDerivedFrom()); DocumentObject* object = nullptr; if (!name.empty() && file.empty()) { - DocumentObject* parent = static_cast(getContainer()); - Document* document = parent->getDocument(); - object = document ? document->getObject(name.c_str()) : nullptr; - if (!object) { - if (reader.isVerbose()) { + if (auto parent = freecad_cast(getContainer())) { + Document* document = parent->getDocument(); + object = document ? document->getObject(name.c_str()) : nullptr; + if (!object && reader.isVerbose()) { FC_WARN("Lost link to '" << name << "' while loading, maybe " "an object was not loaded correctly");