diff --git a/src/BRepExtrema/BRepExtrema_ExtCC.cxx b/src/BRepExtrema/BRepExtrema_ExtCC.cxx index c4fbdc97eb..e66a067431 100644 --- a/src/BRepExtrema/BRepExtrema_ExtCC.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtCC.cxx @@ -40,7 +40,9 @@ BRepExtrema_ExtCC::BRepExtrema_ExtCC(const TopoDS_Edge& E1, const TopoDS_Edge& E void BRepExtrema_ExtCC::Initialize(const TopoDS_Edge& E2) { - Standard_Real V1,V2; + if (!BRep_Tool::IsGeometric(E2)) + return; // protect against non-geometric type (e.g. polygon) + Standard_Real V1, V2; BRepAdaptor_Curve Curv(E2); myHC = new BRepAdaptor_HCurve(Curv); Standard_Real Tol = Min(BRep_Tool::Tolerance(E2), Precision::Confusion()); @@ -57,6 +59,8 @@ void BRepExtrema_ExtCC::Initialize(const TopoDS_Edge& E2) void BRepExtrema_ExtCC::Perform(const TopoDS_Edge& E1) { + if (!BRep_Tool::IsGeometric(E1)) + return; // protect against non-geometric type (e.g. polygon) Standard_Real U1, U2; BRepAdaptor_Curve Curv(E1); Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(Curv); diff --git a/src/BRepExtrema/BRepExtrema_ExtCF.cxx b/src/BRepExtrema/BRepExtrema_ExtCF.cxx index 897f2018c1..59d67b3c44 100644 --- a/src/BRepExtrema/BRepExtrema_ExtCF.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtCF.cxx @@ -45,6 +45,9 @@ BRepExtrema_ExtCF::BRepExtrema_ExtCF(const TopoDS_Edge& E, const TopoDS_Face& F) void BRepExtrema_ExtCF::Initialize(const TopoDS_Edge& E, const TopoDS_Face& F) { BRepAdaptor_Surface Surf(F); + if (Surf.GetType() == GeomAbs_OtherSurface || + !BRep_Tool::IsGeometric(E)) + return; // protect against non-geometric type (e.g. triangulation) BRepAdaptor_Curve aC(E); myHS = new BRepAdaptor_HSurface(Surf); Standard_Real aTolC, aTolS; @@ -73,6 +76,9 @@ void BRepExtrema_ExtCF::Perform(const TopoDS_Edge& E, const TopoDS_Face& F2) myPointsOnS.Clear(); myPointsOnC.Clear(); + if (myHS.IsNull()) + return; // protect against non-geometric type (e.g. triangulation) + Standard_Real U1, U2; BRep_Tool::Range(E, U1, U2); diff --git a/src/BRepExtrema/BRepExtrema_ExtFF.cxx b/src/BRepExtrema/BRepExtrema_ExtFF.cxx index 0881dcc4cb..e777f25cc6 100644 --- a/src/BRepExtrema/BRepExtrema_ExtFF.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtFF.cxx @@ -46,6 +46,9 @@ BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2) { BRepAdaptor_Surface Surf(F2); + if (Surf.GetType() == GeomAbs_OtherSurface) + return; // protect against non-geometric type (e.g. triangulation) + myHS = new BRepAdaptor_HSurface(Surf); Standard_Real Tol = Min(BRep_Tool::Tolerance(F2), Precision::Confusion()); Tol = Min(Surf.UResolution(Tol), Surf.VResolution(Tol)); @@ -67,6 +70,9 @@ void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2) myPointsOnS2.Clear(); BRepAdaptor_Surface Surf1(F1); + if (myHS.IsNull() || Surf1.GetType() == GeomAbs_OtherSurface) + return; // protect against non-geometric type (e.g. triangulation) + Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1); Standard_Real Tol1 = Min(BRep_Tool::Tolerance(F1), Precision::Confusion()); Tol1 = Min(Surf1.UResolution(Tol1), Surf1.VResolution(Tol1)); diff --git a/src/BRepExtrema/BRepExtrema_ExtPC.cxx b/src/BRepExtrema/BRepExtrema_ExtPC.cxx index 4c491c8863..a74939ca8a 100644 --- a/src/BRepExtrema/BRepExtrema_ExtPC.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtPC.cxx @@ -41,7 +41,9 @@ BRepExtrema_ExtPC::BRepExtrema_ExtPC(const TopoDS_Vertex& V, const TopoDS_Edge& void BRepExtrema_ExtPC::Initialize(const TopoDS_Edge& E) { - Standard_Real U1,U2; + if (!BRep_Tool::IsGeometric(E)) + return; // protect against non-geometric type (e.g. polygon) + Standard_Real U1, U2; BRepAdaptor_Curve Curv(E); myHC = new BRepAdaptor_HCurve(Curv); Standard_Real Tol = Min(BRep_Tool::Tolerance(E), Precision::Confusion()); @@ -57,6 +59,9 @@ void BRepExtrema_ExtPC::Initialize(const TopoDS_Edge& E) void BRepExtrema_ExtPC::Perform(const TopoDS_Vertex& V) { - gp_Pnt P = BRep_Tool::Pnt(V); - myExtPC.Perform(P); + if (!myHC.IsNull()) + { + gp_Pnt P = BRep_Tool::Pnt(V); + myExtPC.Perform(P); + } } diff --git a/src/BRepExtrema/BRepExtrema_ExtPF.cxx b/src/BRepExtrema/BRepExtrema_ExtPF.cxx index 5b2d4be300..41493900b9 100644 --- a/src/BRepExtrema/BRepExtrema_ExtPF.cxx +++ b/src/BRepExtrema/BRepExtrema_ExtPF.cxx @@ -49,6 +49,10 @@ void BRepExtrema_ExtPF::Initialize(const TopoDS_Face& TheFace, // cette surface doit etre en champ. Extrema ne fait // pas de copie et prend seulement un pointeur dessus. mySurf.Initialize(TheFace, Standard_False); + + if (mySurf.GetType() == GeomAbs_OtherSurface) + return; // protect against non-geometric type (e.g. triangulation) + Standard_Real Tol = Min(BRep_Tool::Tolerance(TheFace), Precision::Confusion()); Standard_Real aTolU, aTolV; aTolU = Max(mySurf.UResolution(Tol), Precision::PConfusion()); @@ -71,6 +75,9 @@ void BRepExtrema_ExtPF::Perform(const TopoDS_Vertex& TheVertex, const TopoDS_Fac myPoints.Clear(); const gp_Pnt P = BRep_Tool::Pnt(TheVertex); + if (mySurf.GetType() == GeomAbs_OtherSurface) + return; // protect against non-geometric type (e.g. triangulation) + myExtPS.Perform(P); // Exploration of points and classification diff --git a/src/BRepGProp/BRepGProp.cxx b/src/BRepGProp/BRepGProp.cxx index 14dca7b99b..4cc0f1da40 100644 --- a/src/BRepGProp/BRepGProp.cxx +++ b/src/BRepGProp/BRepGProp.cxx @@ -170,6 +170,7 @@ static Standard_Real volumeProperties(const TopoDS_Shape& S, GProp_GProps& Props BRepGProp_Domain BD; TopTools_MapOfShape aFwdFMap; TopTools_MapOfShape aRvsFMap; + TopLoc_Location aLocDummy; for (ex.Init(S,TopAbs_FACE), i = 1; ex.More(); ex.Next(), i++) { const TopoDS_Face& F = TopoDS::Face(ex.Current()); @@ -187,6 +188,15 @@ static Standard_Real volumeProperties(const TopoDS_Shape& S, GProp_GProps& Props continue; } } + { + const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface (F, aLocDummy); + if (aSurf.IsNull()) + { + // skip faces without geometry + continue; + } + } + if (isFwd || isRvs){ BF.Load(F); TopoDS_Iterator aWIter(F); @@ -306,6 +316,7 @@ static Standard_Real volumePropertiesGK(const TopoDS_Shape &theShape, Standard_Real anError = 0.; TopTools_MapOfShape aFwdFMap; TopTools_MapOfShape aRvsFMap; + TopLoc_Location aLocDummy; aVProps.SetLocation(aLoc); @@ -325,6 +336,15 @@ static Standard_Real volumePropertiesGK(const TopoDS_Shape &theShape, continue; } } + { + const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface (aFace, aLocDummy); + if (aSurf.IsNull()) + { + // skip faces without geometry + continue; + } + } + if (isFwd || isRvs){ aPropFace.Load(aFace); @@ -444,6 +464,7 @@ static Standard_Real volumePropertiesGK(const TopoDS_Shape &theShape, Standard_Real anError = 0.; TopTools_MapOfShape aFwdFMap; TopTools_MapOfShape aRvsFMap; + TopLoc_Location aLocDummy; aVProps.SetLocation(aLoc); @@ -463,6 +484,15 @@ static Standard_Real volumePropertiesGK(const TopoDS_Shape &theShape, continue; } } + { + const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface (aFace, aLocDummy); + if (aSurf.IsNull()) + { + // skip faces without geometry + continue; + } + } + if (isFwd || isRvs){ aPropFace.Load(aFace); diff --git a/src/BRepTest/BRepTest_ExtremaCommands.cxx b/src/BRepTest/BRepTest_ExtremaCommands.cxx index 73ccbfd4d6..3fb1887f90 100644 --- a/src/BRepTest/BRepTest_ExtremaCommands.cxx +++ b/src/BRepTest/BRepTest_ExtremaCommands.cxx @@ -138,8 +138,7 @@ static Standard_Integer distmini(Draw_Interpretor& di, Standard_Integer n, const } - else di << "probleme\n"; - //else cout << "probleme"<< endl; + else di << "problem: no distance is found\n"; return 0; } diff --git a/tests/bugs/modalg_6/bug27992 b/tests/bugs/modalg_6/bug27992 new file mode 100644 index 0000000000..52271234da --- /dev/null +++ b/tests/bugs/modalg_6/bug27992 @@ -0,0 +1,17 @@ +puts "========" +puts "OCC27992" +puts "========" +puts "" +################################################# +# Extrema_ExtPS crashes on face without geometric surface +################################################# + +restore [locate_data_file bug27821_nullsurf.brep] a + +# check for exceptions for vertex-face +vertex v 0 0 0 +distmini d v a + +# check for exceptions for face-face +tcopy a b +distmini d a b diff --git a/tests/bugs/vis/bug27821 b/tests/bugs/vis/bug27821 index 0e30cfef01..96c3eb2523 100644 --- a/tests/bugs/vis/bug27821 +++ b/tests/bugs/vis/bug27821 @@ -7,8 +7,9 @@ pload MODELING VISUALIZATION restore [locate_data_file bug27821_nullsurf.brep] s explode s F -# check that sprops does not crash on NULL surface +# check that sprops and vprops do not crash on NULL surface sprops s +vprops s # check that AIS_Shape does not crash on NULL surface vclear