From 6b84b65841cf1a906de0cde7b5238b0bd036dcf3 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sat, 15 Jun 2024 19:51:25 -0400 Subject: [PATCH] [TD]fix segfault on confused selection - failure in DrawDimHelper when both 2d & 3d geom selected --- src/Mod/TechDraw/App/DrawDimHelper.cpp | 6 +++++- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 13 +++++++++++++ src/Mod/TechDraw/Gui/DimensionValidators.cpp | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawDimHelper.cpp b/src/Mod/TechDraw/App/DrawDimHelper.cpp index e07968d1a7..cb445b9811 100644 --- a/src/Mod/TechDraw/App/DrawDimHelper.cpp +++ b/src/Mod/TechDraw/App/DrawDimHelper.cpp @@ -336,7 +336,11 @@ DrawDimHelper::minMax3d(DrawViewPart* dvp, ReferenceVector references, int direc TopoDS_Compound comp; builder.MakeCompound(comp); for (auto& ref : references) { - builder.Add(comp, ref.getGeometry()); + auto tempGeom = ref.getGeometry(); + if (tempGeom.IsNull()) { + continue; + } + builder.Add(comp, tempGeom); } Base::Vector3d centroid = dvp->getOriginalCentroid(); TopoDS_Shape centeredShape =//this result is a throw away. We will work with comp. diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index a6b1494f14..e388663b3b 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -2513,6 +2513,19 @@ void execExtent(Gui::Command* cmd, const std::string& dimType) TechDraw::DrawViewPart* partFeat = TechDraw::getReferencesFromSelection(references2d, references3d); + // if sticky selection is in use we may get confusing selections that appear to + // include both 2d and 3d geometry for the extent dim. + if (!references3d.empty()) { + for (auto& ref : references2d) { + if (!ref.getSubName().empty()) { + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("Incorrect selection"), + QObject::tr("Selection contains both 2d and 3d geometry")); + return; + } + } + } + //Define the geometric configuration required for a extent dimension StringVector acceptableGeometry({"Edge"}); std::vector minimumCounts({1}); diff --git a/src/Mod/TechDraw/Gui/DimensionValidators.cpp b/src/Mod/TechDraw/Gui/DimensionValidators.cpp index 0e2daadc29..2b7ffd02d5 100644 --- a/src/Mod/TechDraw/Gui/DimensionValidators.cpp +++ b/src/Mod/TechDraw/Gui/DimensionValidators.cpp @@ -59,6 +59,7 @@ TechDraw::DrawViewPart* TechDraw::getReferencesFromSelection(ReferenceVector& re //subName to a null string to avoid later misunderstandings. ReferenceEntry ref(dvp, std::string()); references2d.push_back(ref); + continue; } for (auto& sub : selItem.getSubNames()) { ReferenceEntry ref(dvp, sub); @@ -192,7 +193,6 @@ DimensionGeometryType TechDraw::validateDimSelection3d( } } - //check for invalid geometry descriptors in the subNames std::unordered_set acceptableGeometrySet(acceptableGeometry.begin(), acceptableGeometry.end());