From 5c40496cf3b5939b96a0179eec1918754378aeaf Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 12 Sep 2018 19:01:25 +0200 Subject: [PATCH] fixes #0003514: Program crashes when user try to add (by mistake) the origin to a group --- src/Mod/PartDesign/App/Body.cpp | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index e7c3878fe6..41a7caca1f 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -133,22 +133,25 @@ App::DocumentObject* Body::getPrevFeature(App::DocumentObject *start) const App::DocumentObject* Body::getPrevSolidFeature(App::DocumentObject *start) { - if ( !start ) { // default to tip + if (!start) { // default to tip start = Tip.getValue(); } - if ( !start ) { // No Tip + if (!start) { // No Tip return nullptr; } + if (!hasObject(start)) return nullptr; const std::vector & features = Group.getValues(); - auto startIt = std::find ( features.rbegin(), features.rend(), start ); - assert ( startIt != features.rend() ); - auto rvIt = std::find_if ( startIt + 1, features.rend(), isSolidFeature ); + auto startIt = std::find (features.rbegin(), features.rend(), start); + if (startIt == features.rend()) { // object not found + return nullptr; + } + auto rvIt = std::find_if (startIt + 1, features.rend(), isSolidFeature); if (rvIt != features.rend()) { // the solid found in model list return *rvIt; } @@ -158,33 +161,32 @@ App::DocumentObject* Body::getPrevSolidFeature(App::DocumentObject *start) App::DocumentObject* Body::getNextSolidFeature(App::DocumentObject *start) { - if ( !start ) { // default to tip + if (!start) { // default to tip start = Tip.getValue(); } - if ( !start || !hasObject(start) ) { // no or faulty tip + if (!start || !hasObject(start)) { // no or faulty tip return nullptr; } - assert ( hasObject ( start ) ); - const std::vector & features = Group.getValues(); std::vector::const_iterator startIt; - startIt = std::find ( features.begin(), features.end(), start ); - assert ( startIt != features.end() ); - startIt++; - - if (startIt == features.end() ) { // features list is empty + startIt = std::find (features.begin(), features.end(), start); + if (startIt == features.end()) { // object not found return nullptr; } - auto rvIt = std::find_if ( startIt, features.end(), isSolidFeature ); + startIt++; + if (startIt == features.end()) { // features list has only one element + return nullptr; + } + auto rvIt = std::find_if (startIt, features.end(), isSolidFeature); if (rvIt != features.end()) { // the solid found in model list return *rvIt; } - + return nullptr; }