From: azv Date: Wed, 30 Sep 2015 07:48:34 +0000 (+0300) Subject: Avoid crash opening a study (issue #1032) X-Git-Tag: V_1.4.0_demo1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a806e1e6dc47aca84c41c173144a4237616e551a;p=modules%2Fshaper.git Avoid crash opening a study (issue #1032) Rebuild the entity if it was removed by storage. --- diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 187a7cae5..11cdff04b 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -647,15 +647,16 @@ Slvs_hEntity SketchSolver_Constraint::getId(FeaturePtr theFeature) const std::map::const_iterator aFIter = myFeatureMap.find(theFeature); if (aFIter == myFeatureMap.end()) return SLVS_E_UNKNOWN; - // check the Feature is really in the storage - Slvs_Entity anEntity = myStorage->getEntity(aFIter->second); - if (anEntity.h == SLVS_E_UNKNOWN) { - // rebuild feature - int aType; - anEntity.h = const_cast(this)->changeEntity(aFIter->first, aType); - const_cast(this)->myFeatureMap[theFeature] = anEntity.h; - } - return anEntity.h; + //// check the Feature is really in the storage + //Slvs_Entity anEntity = myStorage->getEntity(aFIter->second); + //if (anEntity.h == SLVS_E_UNKNOWN) { + // // rebuild feature + // int aType; + // anEntity.h = const_cast(this)->changeEntity(aFIter->first, aType); + // const_cast(this)->myFeatureMap[theFeature] = anEntity.h; + //} + //return anEntity.h; + return aFIter->second; } Slvs_hEntity SketchSolver_Constraint::getId(AttributePtr theAttribute) const diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index b767b3bb8..5a9652fe6 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -138,6 +138,15 @@ bool SketchSolver_Group::isInteract( return myFeatureStorage->isInteract(std::dynamic_pointer_cast(theFeature)); } +// check the entity is really exists +static void checkEntity(StoragePtr theStorage, Slvs_hEntity& theEntity) +{ + if (theEntity == SLVS_E_UNKNOWN) + return; + Slvs_Entity anEnt = theStorage->getEntity(theEntity); + theEntity = anEnt.h; +} + // ============================================================================ // Function: getFeatureId // Class: SketchSolver_Group @@ -152,13 +161,16 @@ Slvs_hEntity SketchSolver_Group::getFeatureId(FeaturePtr theFeature) const ConstraintConstraintMap::const_iterator aCIter = myConstraints.begin(); for (; aCIter != myConstraints.end(); ++aCIter) { aResult = aCIter->second->getId(theFeature); + checkEntity(myStorage, aResult); if (aResult != SLVS_E_UNKNOWN) return aResult; } // The feature is not found, check it in the temporary constraints std::set::iterator aTmpCIter = myTempConstraints.begin(); - for (; aTmpCIter != myTempConstraints.end() && aResult == SLVS_E_UNKNOWN; ++aTmpCIter) + for (; aTmpCIter != myTempConstraints.end() && aResult == SLVS_E_UNKNOWN; ++aTmpCIter) { aResult = (*aTmpCIter)->getId(theFeature); + checkEntity(myStorage, aResult); + } return aResult; } @@ -176,18 +188,23 @@ Slvs_hEntity SketchSolver_Group::getAttributeId(AttributePtr theAttribute) const ConstraintConstraintMap::const_iterator aCIter = myConstraints.begin(); for (; aCIter != myConstraints.end(); ++aCIter) { aResult = aCIter->second->getId(theAttribute); + checkEntity(myStorage, aResult); if (aResult != SLVS_E_UNKNOWN) return aResult; } // The attribute is not found, check it in the temporary constraints std::set::const_iterator aTmpCIter = myTempConstraints.begin(); - for (; aTmpCIter != myTempConstraints.end() && aResult == SLVS_E_UNKNOWN; ++aTmpCIter) + for (; aTmpCIter != myTempConstraints.end() && aResult == SLVS_E_UNKNOWN; ++aTmpCIter) { aResult = (*aTmpCIter)->getId(theAttribute); + checkEntity(myStorage, aResult); + } // Last chance to find attribute in parametric constraints std::map::const_iterator aParIter = myParametricConstraints.find(theAttribute); - if (aParIter != myParametricConstraints.end()) + if (aParIter != myParametricConstraints.end()) { aResult = aParIter->second->getId(theAttribute); + checkEntity(myStorage, aResult); + } return aResult; }