From 6b3936c8b8859f8d45a1f3e9859ef7e7bde5b271 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 11 Jan 2021 15:31:41 +0100 Subject: [PATCH] Sketcher: [skip ci] fix segmentation fault in ViewProviderSketch::drawConstraintIcons() For more details see: https://forum.freecadweb.org/viewtopic.php?f=19&t=54193 --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index a6fb431b9a08..58953462d284 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -3379,6 +3379,7 @@ void ViewProviderSketch::drawConstraintIcons() // Find the Constraint Icon SoImage Node SoSeparator *sep = static_cast(edit->constrGroup->getChild(constrId)); + int numChildren = sep->getNumChildren(); SbVec3f absPos; // Somewhat hacky - we use SoZoomTranslations for most types of icon, @@ -3442,14 +3443,16 @@ void ViewProviderSketch::drawConstraintIcons() // So, to get the position of the second icon, we add the two translations together // // See note ~30 lines up. - translationPtr = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION)); - if(dynamic_cast(translationPtr)) - thisIcon.position += static_cast(translationPtr)->abPos.getValue(); - else - thisIcon.position += translationPtr->translation.getValue(); + if (numChildren > CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTID) { + translationPtr = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION)); + if(dynamic_cast(translationPtr)) + thisIcon.position += static_cast(translationPtr)->abPos.getValue(); + else + thisIcon.position += translationPtr->translation.getValue(); - thisIcon.destination = dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_ICON)); - thisIcon.infoPtr = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTID)); + thisIcon.destination = dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_ICON)); + thisIcon.infoPtr = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTID)); + } } else { if ((*it)->Name.empty())