From 84bd25527cff0419cc6fdd6f17dcc3d42051de47 Mon Sep 17 00:00:00 2001 From: nbv Date: Fri, 16 Sep 2016 15:31:29 +0300 Subject: [PATCH] 0027875: GeomFill_NSections constructor crash on sequence of curve containing only one curve The GeomFill_NSections algorithm cannot create any surface from sequence with single curve only. Therefore, return is provided in corresponding place of the code. Additionally, some public methods of GeomFill_NSections class checks if the surface has been created earlier. Test case for this issue has been created. Compiler error has been eliminated. --- src/GeomFill/GeomFill_NSections.cxx | 48 ++++++++++++++++++++++++----- src/QABugs/QABugs_20.cxx | 29 +++++++++++++++++ tests/bugs/modalg_6/bug27875 | 19 ++++++++++++ 3 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 tests/bugs/modalg_6/bug27875 diff --git a/src/GeomFill/GeomFill_NSections.cxx b/src/GeomFill/GeomFill_NSections.cxx index 1a85a22169..a7a2ad4bbb 100644 --- a/src/GeomFill/GeomFill_NSections.cxx +++ b/src/GeomFill/GeomFill_NSections.cxx @@ -524,6 +524,12 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, Standard_Real myPres3d = 1.e-06; Standard_Integer i,j,jdeb=1,jfin=mySections.Length(); + if (jfin <= jdeb) + { + //We will not be able to create surface from single curve. + return; + } + GeomFill_SectionGenerator section; Handle(Geom_BSplineSurface) surface; @@ -641,9 +647,12 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, Standard_Integer& NbKnots, Standard_Integer& Degree) const { - NbPoles = mySurface->NbUPoles(); - NbKnots = mySurface->NbUKnots(); - Degree = mySurface->UDegree(); + if (mySurface.IsNull()) + return; + + NbPoles = mySurface->NbUPoles(); + NbKnots = mySurface->NbUKnots(); + Degree = mySurface->UDegree(); } //======================================================= @@ -651,7 +660,8 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= void GeomFill_NSections::Knots(TColStd_Array1OfReal& TKnots) const { - mySurface->UKnots(TKnots); + if (!mySurface.IsNull()) + mySurface->UKnots(TKnots); } //======================================================= @@ -659,7 +669,8 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= void GeomFill_NSections::Mults(TColStd_Array1OfInteger& TMults) const { - mySurface->UMultiplicities(TMults); + if (!mySurface.IsNull()) + mySurface->UMultiplicities(TMults); } @@ -668,7 +679,10 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= Standard_Boolean GeomFill_NSections::IsRational() const { - return mySurface->IsURational(); + if (!mySurface.IsNull()) + return mySurface->IsURational(); + + return Standard_False; } //======================================================= @@ -676,7 +690,10 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= Standard_Boolean GeomFill_NSections::IsUPeriodic() const { - return mySurface->IsUPeriodic(); + if (!mySurface.IsNull()) + return mySurface->IsUPeriodic(); + + return Standard_False; } //======================================================= @@ -684,7 +701,10 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= Standard_Boolean GeomFill_NSections::IsVPeriodic() const { - return mySurface->IsVPeriodic(); + if (!mySurface.IsNull()) + return mySurface->IsVPeriodic(); + + return Standard_False; } //======================================================= @@ -692,6 +712,9 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= Standard_Integer GeomFill_NSections::NbIntervals(const GeomAbs_Shape S) const { + if (mySurface.IsNull()) + return 0; + GeomAdaptor_Surface AdS(mySurface); return AdS.NbVIntervals(S); } @@ -703,6 +726,9 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, void GeomFill_NSections::Intervals(TColStd_Array1OfReal& T, const GeomAbs_Shape S) const { + if (mySurface.IsNull()) + return; + GeomAdaptor_Surface AdS(mySurface); AdS.VIntervals(T,S); } @@ -763,6 +789,9 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, gp_Pnt P, Bary; Bary.SetCoord(0., 0., 0.); + if (mySurface.IsNull()) + return Bary; + Standard_Integer ii,jj; Standard_Real U0, U1, V0, V1; mySurface->Bounds(U0,U1,V0,V1); @@ -801,6 +830,9 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC, //======================================================= void GeomFill_NSections::GetMinimalWeight(TColStd_Array1OfReal& Weights) const { + if (mySurface.IsNull()) + return; + if (mySurface->IsURational()) { Standard_Integer NbU = mySurface->NbUPoles(), NbV = mySurface->NbVPoles(); diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index eae027dba5..ffe937e785 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -2114,6 +2114,33 @@ static Standard_Integer OCC27552(Draw_Interpretor&, return 0; } +#include +static Standard_Integer OCC27875(Draw_Interpretor& theDI, + Standard_Integer theNArg, + const char ** theArgVal) +{ + if (theNArg < 2) + { + theDI << "Use: OCC27875 curve\n"; + } + + TColGeom_SequenceOfCurve aNC(new NCollection_IncAllocator()); + + const Handle(Geom_Curve) aC = Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(theArgVal[1])); + + aNC.Append(aC); + + GeomFill_NSections aNS(aNC); + + if (aNS.BSplineSurface().IsNull()) + { + theDI << "GeomFill_NSections is not done.\n"; + } + + return 0; +} + + void QABugs::Commands_20(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -2132,5 +2159,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { theCommands.Add ("OCC27357", "OCC27357", __FILE__, OCC27357, group); theCommands.Add("OCC26270", "OCC26270 shape result", __FILE__, OCC26270, group); theCommands.Add ("OCC27552", "OCC27552", __FILE__, OCC27552, group); + theCommands.Add("OCC27875", "OCC27875 curve", __FILE__, OCC27875, group); + return; } diff --git a/tests/bugs/modalg_6/bug27875 b/tests/bugs/modalg_6/bug27875 new file mode 100644 index 0000000000..b349d1d646 --- /dev/null +++ b/tests/bugs/modalg_6/bug27875 @@ -0,0 +1,19 @@ +puts "================" +puts "OCC27875" +puts "================" +puts "" +############################### +## GeomFill_NSections constructor crash on sequence of curve containing only one curve +############################### + +# GeomFill_NSections does not work if the sequence of curves contains only single curve. +# Therefore, we should not expect any correct result from this operation. However, the +# exception must not be thrown. + +pload QAcommands + +restore [locate_data_file OCC606_2.brep] w2 +explode w2 e +mkcurve cc w2_1 +trim cc cc +OCC27875 cc