Salome HOME
Avoid of reference to not-initialized attributes values
authormpv <mpv@opencascade.com>
Thu, 18 Aug 2016 11:17:41 +0000 (14:17 +0300)
committermpv <mpv@opencascade.com>
Thu, 18 Aug 2016 11:17:41 +0000 (14:17 +0300)
src/GeomValidators/GeomValidators_ZeroOffset.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp

index 20d324edd59db1d70acaf4c152607a02cf6b75fd..e66cc4333b21256e55797b78894ddb9da9adad57 100644 (file)
@@ -87,11 +87,11 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>&
   double aToSize = 0.0;
   double aFromSize = 0.0;
 
-  if(theFeature->real(*anIt)) {
+  if(theFeature->real(*anIt) && theFeature->real(*anIt)->isInitialized()) {
     aToSize = theFeature->real(*anIt)->value();
   }
   anIt++;
-  if(theFeature->real(*anIt)) {
+  if(theFeature->real(*anIt) && theFeature->real(*anIt)->isInitialized()) {
     aFromSize = theFeature->real(*anIt)->value();
   }
   anIt++;
@@ -109,7 +109,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>&
   std::shared_ptr<GeomAPI_Shape> aFromShape;
 
   std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
-  if(anAttrSel) {
+  if(anAttrSel && anAttrSel->isInitialized()) {
     aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
     if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
       aToShape =  anAttrSel->context()->shape();
@@ -118,13 +118,13 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>&
   anIt++;
 
   std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
-  if(anAttrDouble) {
+  if(anAttrDouble && anAttrDouble->isInitialized()) {
     aToSize = anAttrDouble->value();
   }
   anIt++;
 
   anAttrSel = theFeature->selection(*anIt);
-  if(anAttrSel) {
+  if(anAttrSel && anAttrSel->isInitialized()) {
     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
     if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
       aFromShape = anAttrSel->context()->shape();
@@ -133,7 +133,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>&
   anIt++;
 
   anAttrDouble = theFeature->real(*anIt);
-  if(anAttrDouble) {
+  if(anAttrDouble && anAttrDouble->isInitialized()) {
     aFromSize = anAttrDouble->value();
   }
 
index a36b0a0c1bff9acaffccf8a32258baad5886f09a..6bdd0009b324aa759c1a2eb6b647313f13d68c89 100644 (file)
@@ -137,11 +137,6 @@ bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr
   /// the selection is not possible if the current feature has no presentation for the current
   /// attribute not in AIS not in results. If so, no object in current feature where make
   /// coincidence, so selection is not necessary
-  std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
-  std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(attributeID()));
-  std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
-
   bool aFoundPoint = false;
   GeomShapePtr anAISShape;
   GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(myFeature);
@@ -157,6 +152,10 @@ bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr
     return true;
 
   /// analysis of AIS
+  std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+  std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(attributeID()));
+  std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
   if (anAISShape.get())
     aFoundPoint = shapeContainsPoint(anAISShape, aPoint, mySketch);