From 635616c88fb0230d2cc94b4d6ab05a894bef1852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20M=C3=A1cha?= Date: Mon, 27 May 2024 17:46:02 +0200 Subject: [PATCH] Missing property Object1 or Object2 of fixed joint causing crash (#13912) * Assembly: removal of object of fixed joint causing crash FreeCAD is crashing if the 'Object' property of fixed joint (Assembly/Joints/Fixed/Joint Connector 1/Object1 or Assembly/Joints/Fixed/Joint Connector 2/Object2) is manually removed. Steps to reproduce: - make simple Assembly e.g. of two cubes with Fixed joint - Select Fixed joint in the tree and go-to property 'Data' tab - Select 'Object1' or 'Object2' of the 'Joint Connector 1' or 'Joint Connector 2' and remove this reference - click by your pointing device (mouse) to the arbitrary other property The FreeCAD will crash here because the call App::DocumentObject* obj = getObjFromNameProp(joint, propObjName, propPartName); will return NULL pointer. This problem is similar to the 8d5348ad066aa216c387582bfdcf066966a4fe09. * Assembly: fixed warning message text The warning message text is not describing two cases which can happen, but only one - property of specific joint. * Assembly: avoiding possible crash in rack pinion joint code Similar problems: 07c6df61f8456a6b02e88b369dcef5643ac1574e and 8d5348ad066aa216c387582bfdcf066966a4fe09 were causing real crashes (Linux + Sway Wayland compositor) when Fixed joint type was used. This patch tries to avoid the same situation, but now for the rack pinion joint type. The returned pointer value (part1 and obj1) can get NULL pointer value and is used in the code: if (obj1->getNameInDocument() != part1->getNameInDocument()) { .... a few lines later. --- src/Mod/Assembly/App/AssemblyObject.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index 2866997f49..fa8afb7f1a 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -1166,9 +1166,9 @@ std::string AssemblyObject::handleOneSideOfJoint(App::DocumentObject* joint, App::DocumentObject* part = getLinkObjFromProp(joint, propPartName); App::DocumentObject* obj = getObjFromNameProp(joint, propObjName, propPartName); - if (!part) { - Base::Console().Warning("The property %s or Joint %s is empty.", - propPartName, + if (!part || !obj) { + Base::Console().Warning("The property %s of Joint %s is empty.", + obj ? propPartName : propObjName, joint->getFullName()); return ""; } @@ -1223,6 +1223,13 @@ void AssemblyObject::getRackPinionMarkers(App::DocumentObject* joint, App::DocumentObject* obj2 = getObjFromNameProp(joint, "Object2", "Part2"); Base::Placement plc2 = getPlacementFromProp(joint, "Placement2"); + if (!part1 || !obj1) { + Base::Console().Warning("The property %s of Joint %s is empty.", + obj1 ? "Part1" : "Object1", + joint->getFullName()); + return; + } + // For the pinion nothing special needed : markerNameJ = handleOneSideOfJoint(joint, "Object2", "Part2", "Placement2");