0027991: Modeling Algorithms - BRepGProp_Face crashes on face without geometric surface
authorkgv <kgv@opencascade.com>
Sat, 22 Oct 2016 15:37:51 +0000 (18:37 +0300)
committerapv <apv@opencascade.com>
Fri, 28 Oct 2016 14:26:51 +0000 (17:26 +0300)
BRepGProps now ignores faces without geometric surface to avoid access violation.
BRepExtrema_DistShapeShape::DistanceMapMap() now skips comparison between void bounding boxes.
BRepBndLib::Add() now ignores useTriangulation flag for faces without geometric surfaces, and uses triangulation if any for updating of the box.

src/BRepBndLib/BRepBndLib.cxx
src/BRepExtrema/BRepExtrema_DistShapeShape.cxx
src/BRepGProp/BRepGProp.cxx
tests/bugs/vis/bug27821

index 6e3f6e2..f89d559 100644 (file)
@@ -80,16 +80,15 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
 
   // Add the faces
   BRepAdaptor_Surface BS;
 
   // Add the faces
   BRepAdaptor_Surface BS;
-  Handle(Geom_Surface) GS;
-  Handle(Poly_Triangulation) T;
-  TopLoc_Location l;
+  TopLoc_Location l, aDummyLoc;
   Standard_Integer i, nbNodes;
   BRepAdaptor_Curve BC;
 
   for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
     const TopoDS_Face& F = TopoDS::Face(ex.Current());
   Standard_Integer i, nbNodes;
   BRepAdaptor_Curve BC;
 
   for (ex.Init(S,TopAbs_FACE); ex.More(); ex.Next()) {
     const TopoDS_Face& F = TopoDS::Face(ex.Current());
-    T = BRep_Tool::Triangulation(F, l);
-    if (useTriangulation && !T.IsNull())
+    const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F, l);
+    const Handle(Geom_Surface)& GS = BRep_Tool::Surface (F, aDummyLoc);
+    if ((useTriangulation || GS.IsNull()) && !T.IsNull())
     {
       nbNodes = T->NbNodes();
       const TColgp_Array1OfPnt& Nodes = T->Nodes();
     {
       nbNodes = T->NbNodes();
       const TColgp_Array1OfPnt& Nodes = T->Nodes();
@@ -101,7 +100,6 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
       B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
     } else
     {
       B.Enlarge(T->Deflection() + BRep_Tool::Tolerance(F));
     } else
     {
-      GS = BRep_Tool::Surface(F, l);
       if (!GS.IsNull()) {
         BS.Initialize(F, Standard_False);
         if (BS.GetType() != GeomAbs_Plane) {
       if (!GS.IsNull()) {
         BS.Initialize(F, Standard_False);
         if (BS.GetType() != GeomAbs_Plane) {
@@ -130,7 +128,7 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria
   // Add the edges not in faces
   Handle(TColStd_HArray1OfInteger) HIndices;
   Handle(Poly_PolygonOnTriangulation) Poly;
   // Add the edges not in faces
   Handle(TColStd_HArray1OfInteger) HIndices;
   Handle(Poly_PolygonOnTriangulation) Poly;
-
+  Handle(Poly_Triangulation) T;
   for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
   {
     const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
   for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next())
   {
     const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
index 1d88441..bf380fa 100644 (file)
@@ -117,7 +117,15 @@ void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShap
   {
     for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2)
     {
   {
     for (Standard_Integer anIdx2 = 1; anIdx2 <= aCount2; ++anIdx2)
     {
-      const Standard_Real aDist = theLBox1.Value (anIdx1).Distance (theLBox2.Value (anIdx2));
+      const Bnd_Box& aBox1 = theLBox1.Value (anIdx1);
+      const Bnd_Box& aBox2 = theLBox2.Value (anIdx2);
+      if (aBox1.IsVoid()
+       || aBox2.IsVoid())
+      {
+        continue;
+      }
+
+      const Standard_Real aDist = aBox1.Distance (aBox2);
       if (aDist < myDistRef - myEps || fabs (aDist - myDistRef) < myEps)
       {
         aPairList.Append (BRepExtrema_CheckPair (anIdx1, anIdx2, aDist));
       if (aDist < myDistRef - myEps || fabs (aDist - myDistRef) < myEps)
       {
         aPairList.Append (BRepExtrema_CheckPair (anIdx1, anIdx2, aDist));
index ecaed92..14dca7b 100644 (file)
@@ -91,6 +91,7 @@ static Standard_Real surfaceProperties(const TopoDS_Shape& S, GProp_GProps& Prop
   BRepGProp_Face   BF;
   BRepGProp_Domain BD;
   TopTools_MapOfShape aFMap;
   BRepGProp_Face   BF;
   BRepGProp_Domain BD;
   TopTools_MapOfShape aFMap;
+  TopLoc_Location aLocDummy;
 
   for (ex.Init(S,TopAbs_FACE), i = 1; ex.More(); ex.Next(), i++) {
     const TopoDS_Face& F = TopoDS::Face(ex.Current());
 
   for (ex.Init(S,TopAbs_FACE), i = 1; ex.More(); ex.Next(), i++) {
     const TopoDS_Face& F = TopoDS::Face(ex.Current());
@@ -98,6 +99,16 @@ static Standard_Real surfaceProperties(const TopoDS_Shape& S, GProp_GProps& Prop
     {
       continue;
     }
     {
       continue;
     }
+
+    {
+      const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface (F, aLocDummy);
+      if (aSurf.IsNull())
+      {
+        // skip faces without geometry
+        continue;
+      }
+    }
+
     BF.Load(F);
     TopoDS_Iterator aWIter(F);
     Standard_Boolean IsNatRestr = !aWIter.More();
     BF.Load(F);
     TopoDS_Iterator aWIter(F);
     Standard_Boolean IsNatRestr = !aWIter.More();
index 892a3e6..0e30cfe 100644 (file)
@@ -7,6 +7,10 @@ pload MODELING VISUALIZATION
 restore [locate_data_file bug27821_nullsurf.brep] s
 explode s F
 
 restore [locate_data_file bug27821_nullsurf.brep] s
 explode s F
 
+# check that sprops does not crash on NULL surface
+sprops s
+
+# check that AIS_Shape does not crash on NULL surface
 vclear
 vinit View1
 vaxo
 vclear
 vinit View1
 vaxo