I am trying to evaluate OCC for performing complex boolean operations. I've put together following simple cpp program that demonstrates a possible bug in OCC which leads to perpetual hang with 90% CPU usage by the process.
The program attached is single cpp file, with compilation instructions. Just replace $OCC_INSTALL_DIR by the path in which you have OCC 6.5.3 (or any older version) installed. On successful build and run, it will generate an STL at /tmp/0.stl. If you change the value of TOTAL to be greater than 10, you may see the perpetual hang I am talking about. I can get this program to work for all values of TOTAL < 10 and it hangs for any value >10 that I've tried.
I've compiled and run this program on older versions of OCC (6.5.0, 6.3.0) and I see failures of different kind. Sometimes I get Standard_ConstructionError and other times it hangs as described above. Strangely enough when I run an equivalent program written on top of PythonOCC (which I believe uses same 6.3.0 libraries I used with native program), it runs successfully.
You have to be logged in to download the attached file
Dear Jayesh Salvi,
I would like to inform you that the reported issue was checked.
The problem is not in Boolean operations, but rather in your code.
Which value of the 'step' do you expect if TOTAL > 10 ?
float step = 10/TOTAL;
I guess it will be => 0;
I suggest you to use:
float step = 10.0/TOTAL;
Thanks for pointing that out. After making the change it doesn't hang any more.
I am surprised however that I didn't get an exception or a crash, because I was effectively passing r=0 to MakeCylinder. Instead the library went on executing infinitely.
On Windows platform it leads to crash.
In any case before using Boolean it is better to check
arguments for validity. It will allow you to avoid unexpected behavior
in the future.