0026321: Crash in BRepMesh_FastDiscret::Add
authoroan <oan@opencascade.com>
Tue, 16 Feb 2016 16:08:13 +0000 (19:08 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 8 Apr 2016 08:41:55 +0000 (11:41 +0300)
BRepMesh_FaceAttribute: distinguish constructor and parameters initialization.

src/BRepMesh/BRepMesh_FaceAttribute.cxx
src/BRepMesh/BRepMesh_FaceAttribute.hxx
src/BRepMesh/BRepMesh_FastDiscret.cxx
src/BRepMesh/BRepMesh_FastDiscret.hxx

index 4cba24b..eba74c2 100644 (file)
@@ -47,6 +47,28 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
   init();
 }
 
   init();
 }
 
+//=======================================================================
+//function : Constructor
+//purpose  : 
+//=======================================================================
+BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
+  const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
+  const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints)
+  : myDefFace         (0.),
+    myUMin            (0.),
+    myUMax            (0.),
+    myVMin            (0.),
+    myVMax            (0.),
+    myDeltaX          (1.),
+    myDeltaY          (1.),
+    myMinStep         (-1.),
+    myStatus          (BRepMesh_NoError),
+    myAdaptiveMin     (Standard_False),
+    myBoundaryVertices(theBoundaryVertices),
+    myBoundaryPoints  (theBoundaryPoints)
+{
+}
+
 //=======================================================================
 //function : Constructor
 //purpose  : 
 //=======================================================================
 //function : Constructor
 //purpose  : 
@@ -55,7 +77,7 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
   const TopoDS_Face&                    theFace,
   const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
   const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints,
   const TopoDS_Face&                    theFace,
   const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
   const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints,
-  const Standard_Boolean theAdaptiveMin)
+  const Standard_Boolean                theAdaptiveMin)
   : myDefFace         (0.),
     myUMin            (0.),
     myUMax            (0.),
   : myDefFace         (0.),
     myUMin            (0.),
     myUMax            (0.),
@@ -81,6 +103,20 @@ BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
 {
 }
 
 {
 }
 
+//=======================================================================
+//function : SetFace
+//purpose  : 
+//=======================================================================
+void BRepMesh_FaceAttribute::SetFace (
+  const TopoDS_Face&     theFace, 
+  const Standard_Boolean theAdaptiveMin)
+{
+  myFace        = theFace;
+  myAdaptiveMin = theAdaptiveMin;
+
+  init ();
+}
+
 //=======================================================================
 //function : init
 //purpose  : 
 //=======================================================================
 //function : init
 //purpose  : 
index ffd811e..0460d53 100644 (file)
@@ -29,6 +29,13 @@ class BRepMesh_FaceAttribute : public Standard_Transient
 {
 public:
 
 {
 public:
 
+  //! Constructor. Initializes empty attribute.
+  //! @param theBoundaryVertices shared map of shape vertices.
+  //! @param theBoundaryPoints shared discretization points of shape boundaries.
+  Standard_EXPORT BRepMesh_FaceAttribute(
+    const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
+    const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints);
+
   //! Constructor.
   //! @param theFace face the attribute is created for. 
   //! Used for default initialization. Attribute keeps reference 
   //! Constructor.
   //! @param theFace face the attribute is created for. 
   //! Used for default initialization. Attribute keeps reference 
@@ -41,7 +48,7 @@ public:
     const TopoDS_Face&                    theFace,
     const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
     const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints,
     const TopoDS_Face&                    theFace,
     const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
     const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints,
-    const Standard_Boolean theAdaptiveMin);
+    const Standard_Boolean                theAdaptiveMin);
 
   //! Destructor.
   Standard_EXPORT virtual ~BRepMesh_FaceAttribute();
 
   //! Destructor.
   Standard_EXPORT virtual ~BRepMesh_FaceAttribute();
@@ -54,6 +61,16 @@ public: //! @name main geometrical properties.
     return mySurface;
   }
 
     return mySurface;
   }
 
+  //! Returns True in case if this attribute has already been intialized.
+  inline Standard_Boolean IsInitialized () const
+  {
+    return !myFace.IsNull ();
+  }
+
+  //! Initializes this attribute by the given face.
+  Standard_EXPORT void SetFace (
+    const TopoDS_Face&     theFace, 
+    const Standard_Boolean theAdaptiveMin);
 
   //! Returns forward oriented face to be used for calculations.
   inline const TopoDS_Face& Face() const
 
   //! Returns forward oriented face to be used for calculations.
   inline const TopoDS_Face& Face() const
index e78ba1e..7ed1129 100644 (file)
@@ -179,20 +179,16 @@ void BRepMesh_FastDiscret::resetDataStructure()
 //=======================================================================
 Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
 {
 //=======================================================================
 Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
 {
+  myAttribute.Nullify();
+  GetFaceAttribute(theFace, myAttribute, Standard_True);
+
   try
   {
     OCC_CATCH_SIGNALS
 
     // Initialize face attributes
   try
   {
     OCC_CATCH_SIGNALS
 
     // Initialize face attributes
-    myAttribute.Nullify();
-    GetFaceAttribute(theFace, myAttribute);
-    if (myAttribute.IsNull())
-    {
-      myAttribute = new BRepMesh_FaceAttribute(theFace,
-        myBoundaryVertices, myBoundaryPoints,myParameters.AdaptiveMin);
-
-      myAttributes.Bind(theFace, myAttribute);
-    }
+    if (!myAttribute->IsInitialized ())
+      myAttribute->SetFace (theFace, myParameters.AdaptiveMin);
     
     BRepMesh::HIMapOfInteger&            aVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
     BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = myAttribute->ChangeInternalEdges();
     
     BRepMesh::HIMapOfInteger&            aVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
     BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = myAttribute->ChangeInternalEdges();
@@ -565,15 +561,15 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
       myAttribute->SetDeltaX(deltaX);
       myAttribute->SetDeltaY(deltaY);
     }
       myAttribute->SetDeltaX(deltaX);
       myAttribute->SetDeltaY(deltaY);
     }
+
+    myAttribute->ChangeMeshNodes() = 
+      myAttribute->ChangeStructure()->Data()->Vertices();
   }
   catch(Standard_Failure)
   {
     myAttribute->SetStatus(BRepMesh_Failure);
   }
 
   }
   catch(Standard_Failure)
   {
     myAttribute->SetStatus(BRepMesh_Failure);
   }
 
-  myAttribute->ChangeMeshNodes() = 
-    myAttribute->ChangeStructure()->Data()->Vertices();
-
   myAttribute->ChangeStructure().Nullify();
   return myAttribute->GetStatus();
 }
   myAttribute->ChangeStructure().Nullify();
   return myAttribute->GetStatus();
 }
@@ -923,13 +919,19 @@ void BRepMesh_FastDiscret::storePolygonSharedData(
 //=======================================================================
 Standard_Boolean BRepMesh_FastDiscret::GetFaceAttribute(
   const TopoDS_Face&              theFace,
 //=======================================================================
 Standard_Boolean BRepMesh_FastDiscret::GetFaceAttribute(
   const TopoDS_Face&              theFace,
-  Handle(BRepMesh_FaceAttribute)& theAttribute ) const
+  Handle(BRepMesh_FaceAttribute)& theAttribute,
+  const Standard_Boolean          isForceCreate) const
 {
   if (myAttributes.IsBound(theFace))
   {
     theAttribute = myAttributes(theFace);
     return Standard_True;
   }
 {
   if (myAttributes.IsBound(theFace))
   {
     theAttribute = myAttributes(theFace);
     return Standard_True;
   }
+  else if (isForceCreate)
+  {
+    theAttribute = new BRepMesh_FaceAttribute(myBoundaryVertices, myBoundaryPoints);
+    myAttributes.Bind(theFace, theAttribute);
+  }
 
   return Standard_False;
 }
 
   return Standard_False;
 }
index 8ac5989..be02361 100644 (file)
@@ -154,9 +154,15 @@ public:
     return mySharedFaces;
   }
 
     return mySharedFaces;
   }
 
-  //! Gives face attribute.
-  Standard_EXPORT Standard_Boolean GetFaceAttribute
-    ( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const;
+  //! Returns attribute descriptor for the given face.
+  //! @param theFace face the attribute should be returned for.
+  //! @param[out] theAttribute attribute found for the specified face.
+  //! @param isForceCreate if True creates new attribute in case if there 
+  //! is no data for the given face.
+  Standard_EXPORT Standard_Boolean GetFaceAttribute (
+    const TopoDS_Face&              theFace, 
+    Handle(BRepMesh_FaceAttribute)& theAttribute,
+    const Standard_Boolean          isForceCreate = Standard_False) const;
 
   //! Remove face attribute as useless to free locate memory.
   Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
 
   //! Remove face attribute as useless to free locate memory.
   Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
@@ -346,7 +352,7 @@ private:
   TopoDS_Face                                      myFace;
 
   BRepMesh::DMapOfShapePairOfPolygon               myEdges;
   TopoDS_Face                                      myFace;
 
   BRepMesh::DMapOfShapePairOfPolygon               myEdges;
-  BRepMesh::DMapOfFaceAttribute                    myAttributes;
+  mutable BRepMesh::DMapOfFaceAttribute            myAttributes;
   TopTools_DataMapOfShapeReal                      myMapdefle;
 
   // Data shared for whole shape
   TopTools_DataMapOfShapeReal                      myMapdefle;
 
   // Data shared for whole shape