Infinite loop on cut operation

I am using BRepAlgoAPI_Cut to cut a Compound of Faces with another Compound of Faces. The process occurs interactively. I was forcing the application to perform the algorithm over and over again with different faces that constantly changed. After a few seconds of doing this the application stopped responding. Fortunately, it was running in the debugger, so I was able to find the place it got stuck in.

The function where it occurs is IntTools_FClass2d::Init. The loop begins at line 188 in my copy of inttools_fclass2d.cxx. It is as follows:

do {
gp_Pnt P3db=C3d.Value(u);
if(P3da.SquareDistance(P3db)) {

Local variables:

plbid: 6451.7439502819680
u: 6451.7439502819643
du: 3.6379788070917132e-013

"u+=du" is not updating "u"s value because du is too small. plbid and u are the same up to the 11th decimal, which should be enough to exit the loop. In other words, a precision problem is causing this infinite loop.

Just in case, here is the call stack:

> TKBO.dll!IntTools_FClass2d::Init(const TopoDS_Face & aFace={...}, const double TolUV=9.9999999999999995e-008) Line 194 C++
TKBO.dll!IntTools_FClass2d::IntTools_FClass2d(const TopoDS_Face & aFace={...}, const double TolUV=9.9999999999999995e-008) Line 55 C++
TKBO.dll!IntTools_Context::FClass2d(const TopoDS_Face & aF={...}) Line 54 + 0x2f bytes C++
TKBO.dll!IntTools_Context::StatePointFace(const TopoDS_Face & aF={...}, const gp_Pnt2d & aP2d={...}) Line 385 + 0xc bytes C++
TKBO.dll!IntTools_Context::IsPointInFace(const TopoDS_Face & aF={...}, const gp_Pnt2d & aP2d={...}) Line 397 + 0x10 bytes C++
TKBO.dll!CheckSameDomainFaceInside(const TopoDS_Face & theFace1={...}, const TopoDS_Face & theFace2={...}) Line 1325 + 0x16 bytes C++
TKBO.dll!BOP_ShellSolid::DetectSDFaces() Line 510 + 0x10 bytes C++
TKBO.dll!BOP_ShellSolid::Prepare() Line 612 C++
TKBO.dll!BOP_ShellShell::DoWithFiller(const BOPTools_DSFiller & aDSFiller={...}) Line 100 C++
TKBO.dll!BRepAlgoAPI_BooleanOperation::Build() Line 381 C++
TKBO.dll!BRepAlgoAPI_Cut::BRepAlgoAPI_Cut(const TopoDS_Shape & S1={...}, const TopoDS_Shape & S2={...}) Line 23 C++

Paul Jimenez's picture

Proposed patch:

File: inttools_fclass2d.cxx
Line: 183
From: du=(plbid-pfbid)*0.1;
To: du=(plbid-pfbid+BRep_Tool::Tolerance(edge))*0.1;

I am not sure if that's the best tolerance value to use there, but at least it will guarantee a decent du.


Steve Lockley's picture

Has anyone from OCC looked at this and confirmed it is a valid patch or not?
I had the same problem as described, applied the patch and it worked, but like Paul I don't know if the numbers that are added are doing damage somewhere else. Could the moderator please confirm if this is a valid patch please

Pawel's picture

Hi Steve,

the source code looks the same as before so I think the problem was not registered.

If you have sample data to illustrate the case maybe you can report it using Mantis. Currently, there is an issue - 0021762: Integration new Boolean Operation algorithm to OCC - concerning Boolean operations so there might be a chance that they will have a look at it.