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.
This commit is contained in:
wmayer
2025-03-12 11:43:47 +01:00
committed by Ladislav Michl
parent dace71205f
commit 93ee3a3475

View File

@@ -4281,14 +4281,12 @@ void PropertyXLink::Restore(Base::XMLReader& reader)
name = reader.getAttribute<const char*>("name");
}
assert(getContainer()->isDerivedFrom<App::DocumentObject>());
DocumentObject* object = nullptr;
if (!name.empty() && file.empty()) {
DocumentObject* parent = static_cast<DocumentObject*>(getContainer());
Document* document = parent->getDocument();
object = document ? document->getObject(name.c_str()) : nullptr;
if (!object) {
if (reader.isVerbose()) {
if (auto parent = freecad_cast<DocumentObject*>(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");