0026270: GeomFill_NSections constructor crash
authorema <ema@opencascade.com>
Fri, 8 Jul 2016 11:01:12 +0000 (14:01 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 21 Jul 2016 09:49:08 +0000 (12:49 +0300)
Correction of code to avoid of usage of undefined associated parameters in order not to get exception in constructor.
Creation of test case for this issue

src/GeomFill/GeomFill_NSections.cxx
src/QABugs/QABugs_20.cxx
tests/bugs/modalg_6/bug26270 [new file with mode: 0644]

index 778f14c..1a85a22 100644 (file)
@@ -208,6 +208,10 @@ static void ResultEval(const Handle(Geom_BSplineSurface)& surf,
 GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC)
 {
   mySections = NC;
+  UFirst = 0.;
+  ULast = 1.;
+  VFirst = 0.;
+  VLast = 1.;
   myRefSurf.Nullify();
   ComputeSurface();
 }
@@ -565,16 +569,20 @@ GeomFill_NSections::GeomFill_NSections(const TColGeom_SequenceOfCurve& NC,
 
     Standard_Integer Nbcurves = mySections.Length();
     Standard_Integer Nbpar = myParams.Length();
-    Handle(TColStd_HArray1OfReal) HPar
-      = new TColStd_HArray1OfReal(1,Nbpar);
-    for (i=1;i<=Nbpar;i++) {
-      HPar->SetValue(i,myParams(i));
+    if (Nbpar > 0)
+    {
+      Handle(TColStd_HArray1OfReal) HPar
+        = new TColStd_HArray1OfReal(1, Nbpar);
+      for (i = 1; i <= Nbpar; i++) {
+        HPar->SetValue(i, myParams(i));
+      }
+      section.SetParam(HPar);
     }
-    section.SetParam(HPar);
     section.Perform(Precision::PConfusion());
+    
     Handle(GeomFill_Line) line = new GeomFill_Line(Nbcurves);
     Standard_Integer nbIt = 0, degmin = 2, degmax = 6;
-    Standard_Boolean knownP = Standard_True;
+    Standard_Boolean knownP = Nbpar > 0;
     GeomFill_AppSurf anApprox(degmin, degmax, myPres3d, myPres3d, nbIt, knownP);
     Standard_Boolean SpApprox = Standard_True;
     anApprox.Perform(line, section, SpApprox);
index bf4fba6..2f9ce96 100644 (file)
@@ -2025,6 +2025,60 @@ static Standard_Integer OCC27357(Draw_Interpretor& theDI,
   }
   return 0;
 }
+#include <Standard_ErrorHandler.hxx>
+#include <TColGeom_SequenceOfCurve.hxx>
+#include <GeomFill_NSections.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <TopExp_Explorer.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+//=======================================================================
+//function : OCC26270
+//purpose :
+//=======================================================================
+static Standard_Integer OCC26270(Draw_Interpretor& theDI,
+                                 Standard_Integer theNArg,
+                                 const char **theArgVal)
+{
+  if (theNArg != 3)
+  {
+    theDI << "Usage :" << theArgVal[0] << " shape result\n";
+    return 0;
+  }
+  TopoDS_Shape aShape = DBRep::Get(theArgVal[1]);
+  TopExp_Explorer anExp(aShape, TopAbs_EDGE);
+  TColGeom_SequenceOfCurve aCurveSeq;
+  for (; anExp.More(); anExp.Next())
+  {
+    Standard_Real f, l;
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(anExp.Current()), f, l);
+    if (!aCurve.IsNull())
+    {
+      aCurve = new Geom_TrimmedCurve(aCurve, f, l);
+      aCurveSeq.Append(aCurve);
+    }
+  }
+  if (aCurveSeq.Length() > 1)
+  {
+    try
+    {
+      OCC_CATCH_SIGNALS
+        GeomFill_NSections aBSurface(aCurveSeq);
+      Handle(Geom_BSplineSurface) aRes = aBSurface.BSplineSurface();
+      if (!aRes.IsNull())
+      {
+        BRepBuilderAPI_MakeFace b_face1(aRes, Precision::Confusion());
+        TopoDS_Face bsp_face1 = b_face1.Face();
+        DBRep::Set(theArgVal[2], bsp_face1);
+      }
+    }
+    catch (Standard_Failure)
+    {
+      theDI << "ERROR: Exception in GeomFill_NSections\n";
+    }
+  }
+  return 0;
+}
+
 
 void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
@@ -2042,5 +2096,6 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC26747_2", "OCC26747_2 result", __FILE__, OCC26747_2, group);
   theCommands.Add ("OCC26747_3", "OCC26747_3 result", __FILE__, OCC26747_3, group);
   theCommands.Add ("OCC27357", "OCC27357", __FILE__, OCC27357, group);
+  theCommands.Add("OCC26270", "OCC26270 shape result", __FILE__, OCC26270, group);
   return;
 }
diff --git a/tests/bugs/modalg_6/bug26270 b/tests/bugs/modalg_6/bug26270
new file mode 100644 (file)
index 0000000..263c53a
--- /dev/null
@@ -0,0 +1,10 @@
+pload QAcommands
+puts "================"
+puts "OCC26270"
+puts "================"
+puts ""
+###############################
+## GeomFill_NSections constructor crash
+###############################
+restore [locate_data_file OCC606_2.brep] w2 
+OCC26270 w2 result