From 7e34a29887a288f210715c0a0c776b257052b903 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 8 Apr 2015 12:38:45 +0300 Subject: [PATCH] Avoid crash when removing feature under constraints --- .../SketchSolver_FeatureStorage.cpp | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/SketchSolver/SketchSolver_FeatureStorage.cpp b/src/SketchSolver/SketchSolver_FeatureStorage.cpp index ef8461256..d647d075b 100644 --- a/src/SketchSolver/SketchSolver_FeatureStorage.cpp +++ b/src/SketchSolver/SketchSolver_FeatureStorage.cpp @@ -211,16 +211,32 @@ void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature, Constrain if (aFeatIter == myFeatures.end()) return; // no such feature - std::list anAttributes = theFeature->data()->attributes(std::string()); - std::list::iterator anIter = anAttributes.begin(); - for (; anIter != anAttributes.end(); anIter++) { - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIter); - if (aRefAttr) { - if (!aRefAttr->isObject()) - removeAttribute(aRefAttr->attr(), theFeature); - continue; + if (theFeature->data()) { + std::list anAttributes = theFeature->data()->attributes(std::string()); + std::list::iterator anIter = anAttributes.begin(); + for (; anIter != anAttributes.end(); anIter++) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIter); + if (aRefAttr) { + if (!aRefAttr->isObject()) + removeAttribute(aRefAttr->attr(), theFeature); + continue; + } + removeAttribute(*anIter, theFeature); + } + } else { + // iterate on attributes to find items refered to theFeature + MapAttributeFeature::iterator anIter = myAttributes.begin(); + while (anIter != myAttributes.end()) { + if (anIter->second.find(theFeature) != anIter->second.end()) { + anIter->second.erase(theFeature); + if (anIter->second.empty()) { + MapAttributeFeature::iterator aDeadIter = anIter++; + myAttributes.erase(aDeadIter); + continue; + } + } + anIter++; } - removeAttribute(*anIter, theFeature); } aFeatIter->second.erase(theConstraint); -- 2.39.2