From ca97f1702d25a787c1c1663c4f0cc25784cc3e6f Mon Sep 17 00:00:00 2001 From: asuraven Date: Mon, 17 Jan 2022 11:42:16 +0300 Subject: [PATCH] 0024909: Modeling Algorithms - SIGSEGV in buildsweep Change NCollection_DataMap NCollection_IndexedDataMap to avoid undefined behavior in BRepFill_CompatibleWires::SameNumberByPolarMethod() Correction in BRepFill_PipeShell::Prepare() --- src/BRepFill/BRepFill_CompatibleWires.cxx | 44 +++++++++++-------- src/BRepFill/BRepFill_PipeShell.cxx | 2 + ...Tools_IndexedDataMapOfShapeListOfShape.hxx | 1 + tests/bugs/modalg_7/bug24909_1 | 22 ++++++++++ tests/bugs/modalg_7/bug24909_2 | 29 ++++++++++++ tests/bugs/modalg_7/bug24909_3 | 17 +++++++ 6 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 tests/bugs/modalg_7/bug24909_1 create mode 100644 tests/bugs/modalg_7/bug24909_2 create mode 100644 tests/bugs/modalg_7/bug24909_3 diff --git a/src/BRepFill/BRepFill_CompatibleWires.cxx b/src/BRepFill/BRepFill_CompatibleWires.cxx index ebb01adf79..67ae17f218 100644 --- a/src/BRepFill/BRepFill_CompatibleWires.cxx +++ b/src/BRepFill/BRepFill_CompatibleWires.cxx @@ -389,13 +389,13 @@ static void TrimEdge (const TopoDS_Edge& CurrentEdge, static Standard_Boolean SearchRoot (const TopoDS_Vertex& V, - const TopTools_DataMapOfShapeListOfShape& Map, - TopoDS_Vertex& VRoot) + const TopTools_IndexedDataMapOfShapeListOfShape Map, + TopoDS_Vertex& VRoot) { Standard_Boolean trouve = Standard_False; VRoot.Nullify(); - TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it; - for (it.Initialize(Map); it.More(); it.Next()) { + TopTools_IndexedDataMapIteratorOfDataMapOfShapeListOfShape it(Map); + for (; it.More(); it.Next()) { const TopTools_ListOfShape & List = it.Value(); TopTools_ListIteratorOfListOfShape itL; Standard_Boolean ilyest = Standard_False; @@ -445,12 +445,12 @@ static Standard_Boolean SearchVertex (const TopTools_ListOfShape& List, static Standard_Boolean EdgeIntersectOnWire (const gp_Pnt& P1, - const gp_Pnt& P2, - Standard_Real percent, - const TopTools_DataMapOfShapeListOfShape& Map, - const TopoDS_Wire& W, - TopoDS_Vertex& Vsol, - TopoDS_Wire& newW, + const gp_Pnt& P2, + Standard_Real percent, + const TopTools_IndexedDataMapOfShapeListOfShape& Map, + const TopoDS_Wire& W, + TopoDS_Vertex& Vsol, + TopoDS_Wire& newW, TopTools_DataMapOfShapeSequenceOfShape& theEdgeNewEdges) { @@ -976,7 +976,7 @@ void BRepFill_CompatibleWires:: } // construction of RMap, map of reports of wire i to wire i-1 - TopTools_DataMapOfShapeListOfShape RMap; + TopTools_IndexedDataMapOfShapeListOfShape RMap; RMap.Clear(); // loop on i @@ -997,7 +997,10 @@ void BRepFill_CompatibleWires:: // init of RMap for Vi TopTools_ListOfShape Init; Init.Clear(); - RMap.Bind(Vi,Init); + TopTools_ListOfShape* aShapeList = RMap.ChangeSeek(Vi); + if (!aShapeList) + aShapeList = &RMap(RMap.Add(Vi, Init)); + aShapeList->Append(Init); // it is required to find intersection Vi - wire2 gp_Pnt Pi = BRep_Tool::Pnt(Vi); @@ -1019,14 +1022,14 @@ void BRepFill_CompatibleWires:: RMap,TopoDS::Wire(myWork(i-1)), Vsol,newwire,EdgeNewEdges); if (NewVertex) myWork(i-1) = newwire; - RMap(Vi).Append(Vsol); + RMap.ChangeFromKey(Vi).Append(Vsol); } } // loop on ii } // loop on i // initialisation of MapVLV, map of correspondences vertex - list of vertices - TopTools_DataMapOfShapeListOfShape MapVLV; + TopTools_IndexedDataMapOfShapeListOfShape MapVLV; SeqOfVertices(TopoDS::Wire(myWork(ideb)),SeqV); Standard_Integer SizeMap = SeqV.Length(); MapVLV.Clear(); @@ -1035,13 +1038,16 @@ void BRepFill_CompatibleWires:: TopTools_ListOfShape Init; Init.Clear(); Init.Append(Vi); - MapVLV.Bind(Vi,Init); + TopTools_ListOfShape* aShapeList = MapVLV.ChangeSeek(Vi); + if (!aShapeList) + aShapeList = &MapVLV(MapVLV.Add(Vi, Init)); + aShapeList->Append(Init); Standard_Integer NbV = 1; TopoDS_Vertex V0,V1; V0 = Vi; Standard_Boolean tantque = SearchRoot(V0,RMap,V1); while (tantque) { - MapVLV(Vi).Append(V1); + MapVLV.ChangeFromKey(Vi).Append(V1); NbV++; // test on NbV required for looping sections if (V1.IsSame(Vi) || NbV >= myWork.Length()) { @@ -1076,7 +1082,7 @@ void BRepFill_CompatibleWires:: VRoot.Nullify(); Standard_Boolean intersect = Standard_True; if (SearchRoot(Vi,MapVLV,VRoot)) { - const TopTools_ListOfShape& LVi = MapVLV(VRoot); + const TopTools_ListOfShape& LVi = MapVLV.FindFromKey(VRoot); TopoDS_Vertex VonW; VonW.Nullify(); intersect = (!SearchVertex(LVi,wire2,VonW)); @@ -1102,7 +1108,7 @@ void BRepFill_CompatibleWires:: NewVertex = EdgeIntersectOnWire(Pos->Value(i+1),Pnew,percent, MapVLV,TopoDS::Wire(myWork(i+1)), Vsol,newwire,EdgeNewEdges); - MapVLV(VRoot).Append(Vsol); + MapVLV.ChangeFromKey(VRoot).Append(Vsol); if (NewVertex) myWork(i+1) = newwire; } @@ -1129,7 +1135,7 @@ void BRepFill_CompatibleWires:: Standard_Real U2 = BRep_Tool::Parameter(VL,ECur); BRepAdaptor_Curve Curve(ECur); gp_Pnt PPs = Curve.Value(0.1*(U1+9*U2)); - TopTools_ListIteratorOfListOfShape itF(MapVLV(VF)),itL(MapVLV(VL)); + TopTools_ListIteratorOfListOfShape itF(MapVLV.FindFromKey(VF)),itL(MapVLV.FindFromKey(VL)); Standard_Integer rang = ideb; while (rang < i) { itF.Next(); diff --git a/src/BRepFill/BRepFill_PipeShell.cxx b/src/BRepFill/BRepFill_PipeShell.cxx index e0405b02c2..df85d7cc9f 100644 --- a/src/BRepFill/BRepFill_PipeShell.cxx +++ b/src/BRepFill/BRepFill_PipeShell.cxx @@ -1024,11 +1024,13 @@ void BRepFill_PipeShell::Generated(const TopoDS_Shape& theShape, // place the initial section at the final position Param.Append(V2); WSeq.Append(WSeq(ideb)); + IndSec.Append(WSeq.Length()); } else if (ifin>0) { // place the final section at the initial position Param.Append(V1); WSeq.Append(WSeq(ifin)); + IndSec.Append(WSeq.Length()); } else { // it is necessary to find a medium section to impose by V1 and by V2 diff --git a/src/TopTools/TopTools_IndexedDataMapOfShapeListOfShape.hxx b/src/TopTools/TopTools_IndexedDataMapOfShapeListOfShape.hxx index e637c0387c..d9d427eea5 100644 --- a/src/TopTools/TopTools_IndexedDataMapOfShapeListOfShape.hxx +++ b/src/TopTools/TopTools_IndexedDataMapOfShapeListOfShape.hxx @@ -23,6 +23,7 @@ #include typedef NCollection_IndexedDataMap TopTools_IndexedDataMapOfShapeListOfShape; +typedef NCollection_IndexedDataMap::Iterator TopTools_IndexedDataMapIteratorOfDataMapOfShapeListOfShape; #endif diff --git a/tests/bugs/modalg_7/bug24909_1 b/tests/bugs/modalg_7/bug24909_1 new file mode 100644 index 0000000000..ecda77506e --- /dev/null +++ b/tests/bugs/modalg_7/bug24909_1 @@ -0,0 +1,22 @@ +puts "========" +puts "0024909: Modeling Algorithms - SIGSEGV in buildsweep" +puts "========" +puts "" + +pload MODELING +circle c1 0 0 0 40 +mkedge e1 c1 +wire w1 e1 +tcopy w1 Sketch002 +tcopy w1 Sketch001 +renamevar w1 Sketch +trotate Sketch 0 0 0 0. 1. 0. 90 +ttranslate Sketch 0. 0. 75. +trotate Sketch001 0 0 0 0. 1. 0. 90 +ttranslate Sketch001 0. 0. -75. +ttranslate Sketch002 50. 0. 0. +mksweep Sketch002 +setsweep -CF +addsweep Sketch001 +addsweep Sketch +buildsweep Sweep diff --git a/tests/bugs/modalg_7/bug24909_2 b/tests/bugs/modalg_7/bug24909_2 new file mode 100644 index 0000000000..26bfc46219 --- /dev/null +++ b/tests/bugs/modalg_7/bug24909_2 @@ -0,0 +1,29 @@ +puts "========" +puts "0024909: Modeling Algorithms - SIGSEGV in buildsweep" +puts "========" +puts "" + +puts "REQUIRED All: Standard_ConstructionError: BRepFill :: profiles are inconsistent" + +pload MODELING +restore [locate_data_file bug24909_BezCurve.brep] BezCurve +ttranslate BezCurve 0 -8 0 +explode BezCurve E +wire Sweep001-0-spine BezCurve_1 +mksweep Sweep001-0-spine +setsweep -CF +circle Circle-curve 0 0 0 18 +mkedge Circle-edge Circle-curve 0 0 +wire Circle Circle-edge +trotate Circle 0 0 0 0.577350269189625731 0.577350269189625731 0.577350269189625731 120 +ttranslate Circle 0 -71 203.5 +addsweep Circle +circle Circle001-curve 0 0 0 16 +mkedge Circle001-edge Circle001-curve 0 0 +wire Circle001 Circle001-edge +trotate Circle001 0 0 0 0.577350269189625731 0.577350269189625731 0.577350269189625731 120 +ttranslate Circle001 0 -71 203.5 +addsweep Circle001 + +catch { buildsweep Sweep001 -C -S } message + diff --git a/tests/bugs/modalg_7/bug24909_3 b/tests/bugs/modalg_7/bug24909_3 new file mode 100644 index 0000000000..3cb583a367 --- /dev/null +++ b/tests/bugs/modalg_7/bug24909_3 @@ -0,0 +1,17 @@ +puts "========" +puts "0024909: Modeling Algorithms - SIGSEGV in buildsweep" +puts "========" +puts "" + +pload MODELING +restore [locate_data_file bug24909_spine.brep] +renamevar bug24909_spine Sweep-0-spine +mksweep Sweep-0-spine +setsweep -CF +restore [locate_data_file bug24909_Sketch.brep] +renamevar bug24909_Sketch Sweep-0-section-00-Sketch +addsweep Sweep-0-section-00-Sketch +restore [locate_data_file bug24909_Sketch001.brep] +renamevar bug24909_Sketch001 Sweep-0-section-01-Sketch001 +addsweep Sweep-0-section-01-Sketch001 +buildsweep Sweep