Assembly: fix onChanged crash

This commit is contained in:
PaddleStroke
2025-09-24 15:34:57 +02:00
committed by Chris Hennes
parent 902079af20
commit 5194dfc18a

View File

@@ -105,17 +105,33 @@ void AssemblyLink::onChanged(const App::Property* prop)
if (Rigid.getValue()) { if (Rigid.getValue()) {
// movePlc needs to be computed before updateContents. // movePlc needs to be computed before updateContents.
if (!objLinkMap.empty()) { App::DocumentObject* firstLink = nullptr;
auto firstElement = *objLinkMap.begin(); for (auto* obj : Group.getValues()) {
if (obj
&& (obj->isDerivedFrom<App::Link>() || obj->isDerivedFrom<AssemblyLink>())) {
firstLink = obj;
break;
}
}
App::DocumentObject* obj = firstElement.first; if (firstLink) {
App::DocumentObject* link = firstElement.second; App::DocumentObject* sourceObj = nullptr;
auto* prop = if (auto* link = dynamic_cast<App::Link*>(firstLink)) {
dynamic_cast<App::PropertyPlacement*>(obj->getPropertyByName("Placement")); sourceObj = link->getLinkedObject(false); // Get non-recursive linked object
auto* prop2 = }
dynamic_cast<App::PropertyPlacement*>(link->getPropertyByName("Placement")); else if (auto* asmLink = dynamic_cast<AssemblyLink*>(firstLink)) {
if (prop && prop2) { sourceObj = asmLink->getLinkedAssembly();
movePlc = prop2->getValue() * prop->getValue().inverse(); }
if (sourceObj) {
auto* propSource = dynamic_cast<App::PropertyPlacement*>(
sourceObj->getPropertyByName("Placement"));
auto* propLink = dynamic_cast<App::PropertyPlacement*>(
firstLink->getPropertyByName("Placement"));
if (propSource && propLink) {
movePlc = propLink->getValue() * propSource->getValue().inverse();
}
} }
} }
} }