diff --git a/src/BRepBndLib/BRepBndLib.cxx b/src/BRepBndLib/BRepBndLib.cxx index 6e3f6e28a8..f89d559254 100644 --- a/src/BRepBndLib/BRepBndLib.cxx +++ b/src/BRepBndLib/BRepBndLib.cxx @@ -80,16 +80,15 @@ void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B, Standard_Boolean useTria // 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()); - 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(); @@ -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 { - GS = BRep_Tool::Surface(F, l); 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; - + Handle(Poly_Triangulation) T; for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE); ex.More(); ex.Next()) { const TopoDS_Edge& E = TopoDS::Edge(ex.Current()); diff --git a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx index 1d88441df7..bf380fa350 100644 --- a/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx +++ b/src/BRepExtrema/BRepExtrema_DistShapeShape.cxx @@ -117,7 +117,15 @@ void BRepExtrema_DistShapeShape::DistanceMapMap (const TopTools_IndexedMapOfShap { 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)); diff --git a/src/BRepGProp/BRepGProp.cxx b/src/BRepGProp/BRepGProp.cxx index ecaed92cc1..14dca7b99b 100644 --- a/src/BRepGProp/BRepGProp.cxx +++ b/src/BRepGProp/BRepGProp.cxx @@ -91,6 +91,7 @@ static Standard_Real surfaceProperties(const TopoDS_Shape& S, GProp_GProps& Prop 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()); @@ -98,6 +99,16 @@ static Standard_Real surfaceProperties(const TopoDS_Shape& S, GProp_GProps& Prop { 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(); diff --git a/tests/bugs/vis/bug27821 b/tests/bugs/vis/bug27821 index 892a3e6038..0e30cfef01 100644 --- a/tests/bugs/vis/bug27821 +++ b/tests/bugs/vis/bug27821 @@ -7,6 +7,10 @@ pload MODELING VISUALIZATION 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