0027821: Visualization, AIS_Shape - add NULL checks for displaying TopoDS_Face with...
authorakz <akz@opencascade.com>
Fri, 5 Aug 2016 08:24:58 +0000 (11:24 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 1 Sep 2016 10:19:13 +0000 (13:19 +0300)
src/BRepAdaptor/BRepAdaptor_Surface.cxx
src/BRepTools/BRepTools.cxx
src/Prs3d/Prs3d_ShapeTool.cxx
src/StdPrs/StdPrs_Isolines.cxx
src/StdPrs/StdPrs_WFShape.cxx
tests/bugs/vis/bug27821 [new file with mode: 0644]

index ff31f8a..850face 100644 (file)
@@ -72,13 +72,17 @@ void BRepAdaptor_Surface::Initialize(const TopoDS_Face& F,
 {
   myFace = F;
   TopLoc_Location L;
+  const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface(F, L);
+  if (aSurface.IsNull())
+    return;
+
   if (Restriction) {
     Standard_Real umin,umax,vmin,vmax;
     BRepTools::UVBounds(F,umin,umax,vmin,vmax);
-    mySurf.Load(BRep_Tool::Surface(F,L),umin,umax,vmin,vmax);
+    mySurf.Load(aSurface,umin,umax,vmin,vmax);
   }
   else 
-    mySurf.Load(BRep_Tool::Surface(F,L));
+    mySurf.Load(aSurface);
   myTrsf = L.Transformation();
 }
 
index 706708a..96e83c0 100644 (file)
@@ -74,7 +74,14 @@ void  BRepTools::UVBounds(const TopoDS_Face& F,
 {
   Bnd_Box2d B;
   AddUVBounds(F,B);
-  B.Get(UMin,VMin,UMax,VMax);
+  if (!B.IsVoid())
+  {
+    B.Get(UMin,VMin,UMax,VMax);
+  }
+  else
+  {
+    UMin = UMax = VMin = VMax = 0.0;
+  }
 }
 
 //=======================================================================
@@ -89,7 +96,14 @@ void  BRepTools::UVBounds(const TopoDS_Face& F,
 {
   Bnd_Box2d B;
   AddUVBounds(F,W,B);
-  B.Get(UMin,VMin,UMax,VMax);
+  if (!B.IsVoid())
+  {
+    B.Get(UMin,VMin,UMax,VMax);
+  }
+  else
+  {
+    UMin = UMax = VMin = VMax = 0.0;
+  }
 }
 
 
@@ -105,7 +119,14 @@ void  BRepTools::UVBounds(const TopoDS_Face& F,
 {
   Bnd_Box2d B;
   AddUVBounds(F,E,B);
-  B.Get(UMin,VMin,UMax,VMax);
+  if (!B.IsVoid())
+  {
+    B.Get(UMin,VMin,UMax,VMax);
+  }
+  else
+  {
+    UMin = UMax = VMin = VMax = 0.0;
+  }
 }
 
 //=======================================================================
@@ -130,7 +151,13 @@ void  BRepTools::AddUVBounds(const TopoDS_Face& FF, Bnd_Box2d& B)
   if (aBox.IsVoid()) {
     Standard_Real UMin,UMax,VMin,VMax;
     TopLoc_Location L;
-    BRep_Tool::Surface(F,L)->Bounds(UMin,UMax,VMin,VMax);
+    const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(F, L);
+    if (aSurf.IsNull())
+    {
+      return;
+    }
+
+    aSurf->Bounds(UMin,UMax,VMin,VMax);
     aBox.Update(UMin,VMin,UMax,VMax);
   }
   
@@ -162,7 +189,7 @@ void BRepTools::AddUVBounds(const TopoDS_Face& aF,
                             const TopoDS_Edge& aE,
                             Bnd_Box2d& aB)
 {
-  Standard_Real aT1, aT2, aXmin, aYmin, aXmax, aYmax;
+  Standard_Real aT1, aT2, aXmin = 0.0, aYmin = 0.0, aXmax = 0.0, aYmax = 0.0;
   Standard_Real aUmin, aUmax, aVmin, aVmax;
   Bnd_Box2d aBoxC, aBoxS; 
   TopLoc_Location aLoc;
@@ -173,7 +200,10 @@ void BRepTools::AddUVBounds(const TopoDS_Face& aF,
   }
   //
   BndLib_Add2dCurve::Add(aC2D, aT1, aT2, 0., aBoxC);
-  aBoxC.Get(aXmin, aYmin, aXmax, aYmax);
+  if (!aBoxC.IsVoid())
+  {
+    aBoxC.Get(aXmin, aYmin, aXmax, aYmax);
+  }
   //
   Handle(Geom_Surface) aS = BRep_Tool::Surface(aF, aLoc);
   aS->Bounds(aUmin, aUmax, aVmin, aVmax);
index cf47f64..edb8912 100644 (file)
@@ -147,6 +147,11 @@ Standard_Boolean Prs3d_ShapeTool::IsPlanarFace() const
   TopLoc_Location l;
   const TopoDS_Face& F = TopoDS::Face(myFaceExplorer.Current());
   const Handle(Geom_Surface)& S = BRep_Tool::Surface(F, l);
+  if (S.IsNull())
+  {
+    return Standard_False;
+  }
+
   Handle(Standard_Type) TheType = S->DynamicType();
 
   if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
index ad2b101..15e7a4b 100644 (file)
@@ -178,6 +178,10 @@ void StdPrs_Isolines::AddOnTriangulation (const TopoDS_Face&          theFace,
   // Access surface definition.
   TopLoc_Location aLocSurface;
   Handle(Geom_Surface) aSurface = BRep_Tool::Surface (theFace, aLocSurface);
+  if (aSurface.IsNull())
+  {
+    return;
+  }
 
   // Access triangulation.
   TopLoc_Location aLocTriangulation;
@@ -611,7 +615,11 @@ void StdPrs_Isolines::UVIsoParameters (const TopoDS_Face&      theFace,
   aVmax = Min (aVmax,  theUVLimit);
 
   TopLoc_Location aLocation;
-  Handle(Geom_Surface) aSurface = BRep_Tool::Surface (theFace, aLocation);
+  const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface (theFace, aLocation);
+  if (aSurface.IsNull())
+  {
+    return;
+  }
 
   const Standard_Boolean isUClosed = aSurface->IsUClosed();
   const Standard_Boolean isVClosed = aSurface->IsVClosed();
index 878c4c3..5522ea5 100644 (file)
@@ -304,6 +304,11 @@ void StdPrs_WFShape::addEdgesOnTriangulation (const Handle(Prs3d_Presentation)&
       }
     }
 
+    if (aNbFree == 0)
+    {
+      continue;
+    }
+
     // Allocate the arrays.
     TColStd_Array1OfInteger aFree (1, 2 * aNbFree);
     Standard_Integer aNbInternal = (3 * aNbTriangles - aNbFree) / 2;
diff --git a/tests/bugs/vis/bug27821 b/tests/bugs/vis/bug27821
new file mode 100644 (file)
index 0000000..892a3e6
--- /dev/null
@@ -0,0 +1,20 @@
+puts "========"
+puts "AIS_Shape - displaying TopoDS_Face with NULL surface (test case checks there is no crash)"
+puts "========"
+
+pload MODELING VISUALIZATION
+
+restore [locate_data_file bug27821_nullsurf.brep] s
+explode s F
+
+vclear
+vinit View1
+vaxo
+vdisplay -noupdate -dispMode 0 s
+vaspects s -subshapes s_1 -setcolor RED
+vdisplay -noupdate -dispMode 1 s
+vshowfaceboundary s 1
+vfit
+vselect 250 250
+
+vdump $imagedir/${casename}.png