From 413b1c1a9765c127345ab6175070bbb89af53b6f Mon Sep 17 00:00:00 2001 From: akz Date: Fri, 5 Aug 2016 11:24:58 +0300 Subject: [PATCH] 0027821: Visualization, AIS_Shape - add NULL checks for displaying TopoDS_Face with NULL surface NULL surface --- src/BRepAdaptor/BRepAdaptor_Surface.cxx | 8 +++-- src/BRepTools/BRepTools.cxx | 42 +++++++++++++++++++++---- src/Prs3d/Prs3d_ShapeTool.cxx | 5 +++ src/StdPrs/StdPrs_Isolines.cxx | 10 +++++- src/StdPrs/StdPrs_WFShape.cxx | 5 +++ tests/bugs/vis/bug27821 | 20 ++++++++++++ 6 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 tests/bugs/vis/bug27821 diff --git a/src/BRepAdaptor/BRepAdaptor_Surface.cxx b/src/BRepAdaptor/BRepAdaptor_Surface.cxx index ff31f8a353..850facead9 100644 --- a/src/BRepAdaptor/BRepAdaptor_Surface.cxx +++ b/src/BRepAdaptor/BRepAdaptor_Surface.cxx @@ -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(); } diff --git a/src/BRepTools/BRepTools.cxx b/src/BRepTools/BRepTools.cxx index 706708a77e..96e83c0ec0 100644 --- a/src/BRepTools/BRepTools.cxx +++ b/src/BRepTools/BRepTools.cxx @@ -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); diff --git a/src/Prs3d/Prs3d_ShapeTool.cxx b/src/Prs3d/Prs3d_ShapeTool.cxx index cf47f649b5..edb891254f 100644 --- a/src/Prs3d/Prs3d_ShapeTool.cxx +++ b/src/Prs3d/Prs3d_ShapeTool.cxx @@ -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)) { diff --git a/src/StdPrs/StdPrs_Isolines.cxx b/src/StdPrs/StdPrs_Isolines.cxx index ad2b1017d7..15e7a4b6e5 100644 --- a/src/StdPrs/StdPrs_Isolines.cxx +++ b/src/StdPrs/StdPrs_Isolines.cxx @@ -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(); diff --git a/src/StdPrs/StdPrs_WFShape.cxx b/src/StdPrs/StdPrs_WFShape.cxx index 878c4c3828..5522ea5fe1 100644 --- a/src/StdPrs/StdPrs_WFShape.cxx +++ b/src/StdPrs/StdPrs_WFShape.cxx @@ -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 index 0000000000..892a3e6038 --- /dev/null +++ b/tests/bugs/vis/bug27821 @@ -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 -- 2.39.5