DiscussionsIssue archiveOCCT:Modeling Algorithms

Archived issue #0032744

Modeling Algorithms - Endless loop in GCPnts_UniformDeflection

Open CASCADEOCCT:Modeling Algorithmsclosed16 public notes

Search issues

Description

To reproduce memory leak and endless loop inside GCPnts_UniformDeflection constructor it’s enough to read Attachment 1 (BREP) by BRepTools::Read() function.
To find out why such “valid“ edges are produced by JTCAFControl_Reader converter, you can read JT file and transfer it to TDocStd_Documen document and then iterate through gotten shapes checking each edge by GCPnts_UniformDeflection algorithm.

Steps to reproduce

TopoDS_Compound comp;
BRep_Builder builder;
BRepTools::Read(comp, "/path/to/Attachment 1 (BREP)", builder);
BRepCheck_Analyzer analyzer(comp);
if (analyzer.IsValid()) {
  TopTools_IndexedMapOfShape edges;
  TopExp::MapShapes(comp, TopAbs_EDGE, edges);
  for (auto edgeNum = 1; edgeNum <= edges.Extent(); ++edgeNum)
  {
    auto edge = TopoDS::Edge(edges(edgeNum));
    Standard_Real firstParam = 0., lastParam = 0.;
    auto pCurve = BRep_Tool::Curve(edge, firstParam, lastParam);
    GeomAdaptor_Curve curveAdaptor(pCurve, firstParam, lastParam);
    GCPnts_UniformDeflection uniformAbs(curveAdaptor, 0.001, firstParam, lastParam); // <= endless loop and memory leak inside
  }
}

Additional information

From TSYS-16-006

Public activity

16 archived notes

Participants are labeled by their role within this record.

01Commenter 1
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Mon Dec 20 19:27:09 2021 +0300

    0032744: Modeling Algorithms - Memory leak in GCPnts_UniformDeflection
    
    fixed CPnts_UniformDeflection::More()
02Commenter 1
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
03Commenter 3
In this extremal case the parameter increment in CPnts_UniformDeflection::Perform() is less than the parameter's value precision. For this reason, the parameter value has not been changed, the loop becomes endless.
Tests results are here: http://jenkins-test-occt.nnov.opencascade.com/view/CR32744-master-Author/view/COMPARE/
Unstable cases are different for win & Linux platforms and seems like not related to this issue
04Commenter 4
               myFirstParam == myFirstParam + myDu;

It is better using myDu < Epsilon (myFirstParam)
05Commenter 5
About test case, it is better to read the shape using standard restore command and pass to the test command the shape instead of file name.
06Commenter 1
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
07Commenter 1
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
08Commenter 8
09Commenter 1
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
10Commenter 10
    myFirstParam += myDu;
    myFinish = myLastParam - myFirstParam < myTolCur ||
               Abs(myDu) < myTolCur ||
               // to avoid less than double precision endless increment
               myDu < Epsilon (myFirstParam);

Please compute the value of Epsilon (myFirstParam) before entering the loop. It must be invariant.

  else if (aShape.ShapeType() != TopAbs_EDGE)
  {
    theDi << " Shape type must be EDGE\n";
    return 1;
  }

  const TopoDS_Edge& anEdge = *(TopoDS_Edge*) &aShape

Use the method TopoDS:Edge() for safe downcasting of a shape to edge. After that just check the cast result for null shape.
11Commenter 1
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
12Commenter 12
fixed
13Commenter 1
Branch [archived branch] has been updated forcibly by Author.

[revision removed]
14Commenter 14
For integration:
occt - CR32744
products - none
15Commenter 15
Combination -
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 18220.12000000046 / 18175.980000000385 [+0.24%]
Products
Total CPU difference: 11659.240000000125 / 11591.590000000113 [+0.58%]
Windows-64-VC14:
OCCT
Total CPU difference: 19997.15625 / 19974.59375 [+0.11%]
Products
Total CPU difference: 13120.265625 / 13088.65625 [+0.24%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
16Commenter 1
Branch [archived branch] has been deleted by Participant.

[revision removed]