Assembly: Prevent crash when toggling rigid of grounded sub assembly (#24761)

* Assembly: Prevent crash when toggling rigid of grounded sub assembly

* to squash

* to squash

* Update AssemblyLink.cpp
This commit is contained in:
PaddleStroke
2025-10-21 09:51:15 +02:00
committed by GitHub
parent 0ce82c4159
commit 80f5df8435
3 changed files with 31 additions and 0 deletions

View File

@@ -101,6 +101,26 @@ void AssemblyLink::onChanged(const App::Property* prop)
if (prop == &Rigid) {
Base::Placement movePlc;
// A flexible sub-assembly cannot be grounded.
// If a rigid sub-assembly has an object that is grounded, we also remove it.
auto groundedJoints = getParentAssembly()->getGroundedJoints();
for (auto* joint : groundedJoints) {
auto* propObj =
dynamic_cast<App::PropertyLink*>(joint->getPropertyByName("ObjectToGround"));
if (!propObj) {
continue;
}
auto* groundedObj = propObj->getValue();
if (auto* linkElt = dynamic_cast<App::LinkElement*>(groundedObj)) {
// hasObject does not handle link groups so we must handle it manually.
groundedObj = linkElt->getLinkGroup();
}
if (Rigid.getValue() ? hasObject(groundedObj) : groundedObj == this) {
getDocument()->removeObject(joint->getNameInDocument());
}
}
if (Rigid.getValue()) {
// movePlc needs to be computed before updateContents.
App::DocumentObject* firstLink = nullptr;

View File

@@ -781,6 +781,11 @@ std::unordered_set<App::DocumentObject*> AssemblyObject::getGroundedParts()
if (propObj) {
App::DocumentObject* objToGround = propObj->getValue();
if (objToGround) {
if (auto* asmLink = dynamic_cast<AssemblyLink*>(objToGround)) {
if (!asmLink->isRigid()) {
continue;
}
}
groundedSet.insert(objToGround);
}
}

View File

@@ -628,6 +628,12 @@ bool ViewProviderAssembly::canDragObjectIn3d(App::DocumentObject* obj) const
return false;
}
if (auto* asmLink = dynamic_cast<Assembly::AssemblyLink*>(obj)) {
if (!asmLink->isRigid()) {
return false;
}
}
auto* assemblyPart = getObject<AssemblyObject>();
// Check if the selected object is a child of the assembly