From 5194dfc18adcdcb01b1837c65cae6f005a54f8c0 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Wed, 24 Sep 2025 15:34:57 +0200 Subject: [PATCH] Assembly: fix onChanged crash --- src/Mod/Assembly/App/AssemblyLink.cpp | 36 +++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Mod/Assembly/App/AssemblyLink.cpp b/src/Mod/Assembly/App/AssemblyLink.cpp index f12169669c..cf3231a462 100644 --- a/src/Mod/Assembly/App/AssemblyLink.cpp +++ b/src/Mod/Assembly/App/AssemblyLink.cpp @@ -105,17 +105,33 @@ void AssemblyLink::onChanged(const App::Property* prop) if (Rigid.getValue()) { // movePlc needs to be computed before updateContents. - if (!objLinkMap.empty()) { - auto firstElement = *objLinkMap.begin(); + App::DocumentObject* firstLink = nullptr; + for (auto* obj : Group.getValues()) { + if (obj + && (obj->isDerivedFrom() || obj->isDerivedFrom())) { + firstLink = obj; + break; + } + } - App::DocumentObject* obj = firstElement.first; - App::DocumentObject* link = firstElement.second; - auto* prop = - dynamic_cast(obj->getPropertyByName("Placement")); - auto* prop2 = - dynamic_cast(link->getPropertyByName("Placement")); - if (prop && prop2) { - movePlc = prop2->getValue() * prop->getValue().inverse(); + if (firstLink) { + App::DocumentObject* sourceObj = nullptr; + if (auto* link = dynamic_cast(firstLink)) { + sourceObj = link->getLinkedObject(false); // Get non-recursive linked object + } + else if (auto* asmLink = dynamic_cast(firstLink)) { + sourceObj = asmLink->getLinkedAssembly(); + } + + if (sourceObj) { + auto* propSource = dynamic_cast( + sourceObj->getPropertyByName("Placement")); + auto* propLink = dynamic_cast( + firstLink->getPropertyByName("Placement")); + + if (propSource && propLink) { + movePlc = propLink->getValue() * propSource->getValue().inverse(); + } } } }