From b3bd225a641fef1802f475c677603d5444bdf0f8 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Fri, 18 Jul 2025 16:53:35 +0200 Subject: [PATCH] Assembly: Fix crash 20614 (#22538) --- src/Mod/Assembly/App/AssemblyObject.cpp | 24 +++++++++++++++++++++++- src/Mod/Assembly/App/AssemblyObject.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index b7318f0938..07fc236247 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -1334,7 +1334,7 @@ AssemblyObject::makeMbdJoint(App::DocumentObject* joint) JointType jointType = getJointType(joint); std::shared_ptr mbdJoint = makeMbdJointOfType(joint, jointType); - if (!mbdJoint) { + if (!mbdJoint || !isMbDJointValid(joint)) { return {}; } @@ -1724,6 +1724,28 @@ int AssemblyObject::slidingPartIndex(App::DocumentObject* joint) return slidingFound; } +bool AssemblyObject::isMbDJointValid(App::DocumentObject* joint) +{ + // When dragging a part, we are bundling fixed parts together. + // This may lead to a conflicting joint that is self referencing a MbD part. + // The solver crash when fed such a bad joint. So we make sure it does not happen. + App::DocumentObject* part1 = getMovingPartFromRef(this, joint, "Reference1"); + App::DocumentObject* part2 = getMovingPartFromRef(this, joint, "Reference2"); + if (!part1 || !part2) { + return false; + } + + // If this joint is self-referential it must be ignored. + if (getMbDPart(part1) == getMbDPart(part2)) { + Base::Console().warning( + "Assembly: Ignoring joint (%s) because its parts are connected by a fixed " + "joint bundle. This joint is a conflicting or redundant constraint.\n", + joint->getFullLabel()); + return false; + } + return true; +} + AssemblyObject::MbDPartData AssemblyObject::getMbDData(App::DocumentObject* part) { auto it = objectPartMap.find(part); diff --git a/src/Mod/Assembly/App/AssemblyObject.h b/src/Mod/Assembly/App/AssemblyObject.h index acf19f668b..af63b31e1c 100644 --- a/src/Mod/Assembly/App/AssemblyObject.h +++ b/src/Mod/Assembly/App/AssemblyObject.h @@ -188,6 +188,8 @@ public: std::vector getMotionsFromSimulation(App::DocumentObject* sim); + bool isMbDJointValid(App::DocumentObject* joint); + private: std::shared_ptr mbdAssembly;