A quite strange error occurs when use the "DBRep_IsoBuilder"

jianbaoxia

CAD master
I try to get the hatch of shape follow Quaoar's advice, however, when I instance the class "DBRep_IsoBuilder", I get a so inexplicable bug.
Let me give my simple demo first:
Code:
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS_Edge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS_Face.hxx>
#include <DBRep_IsoBuilder.hxx>

int main(int argc, char** argv)
{
    // build a topo_face
    Standard_Real theXmin = 0.0;
    Standard_Real theXmax = 2.0;
    Standard_Real theZmin = 0.0;
    Standard_Real theZmax = 2.0;
    Standard_Real theY = 0.0;
    gp_Pnt p1(theXmin, theY, theZmin);
    gp_Pnt p2(theXmax, theY, theZmin);
    gp_Pnt p3(theXmax, theY, theZmax);
    gp_Pnt p4(theXmin, theY, theZmax);
    TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(p1, p2);
    TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(p2, p3);
    TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(p3, p4);
    TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(p4, p1);
    TopoDS_Wire w = BRepBuilderAPI_MakeWire(e1, e2, e3, e4);
    TopoDS_Face top_face = BRepBuilderAPI_MakeFace(w);
    //
    DBRep_IsoBuilder IsoBuild(top_face, 100, 10);

    return 0;
}
The OCCT version I use is 7.6.0.
What the demo do is just build a TopoDS_Face, and then get a DBRep_IsoBuilder instance.

First question: when I debug the demo, I get a exception from "Draw_Interpretor.cxx". I didn't call it, I thought this may because the constructor of "DBRep_IsoBuilder" call it. As show below:
1656327255530.png

Second question: This is what make me feel unable to understand!!!:eek:
I annotation the code:
Code:
DBRep_IsoBuilder IsoBuild(top_face, 100, 10);
However, I get the same exception. The demo just only build a TopoDS_Face now. And after I call the constructor of "DBRep_IsoBuilder" and annotation it, I get the same bug, the code of build TopoDS_Face could not work.

Why? I'm so puzzle. o_Oo_Oo_O
 

natalia

Moderator
Staff member
Hi @jianbaoxia,

The case that you’re describing is the same as discussed in https://dev.opencascade.org/content/crash-tkdrawdrawinterpretortclexit.

The reason of it is a link to TKDraw library. When your application performs this linkage, this library creates a variable of Tcl interpretator (Draw_Interpretor theCommands) and at the exit of your application, it tries to remove this instance. Due to this, the destructor of the interpretator is called and you have this crash (Tcl_Exit) in application.

The matter is that, this library is similar to the part of OCCT test application (DRAWEXE) and is not a pretender to use in some application. We may think about it as about an example of some functionality. It’s not the best practice to make a linkage to it in the application. (However, some time ago, I also have the practice to have some linkage, as there was very useful piece of code here and had the similar error as you. And it was only one problem, so the application lived with such a linkage :))

That means that the problem is not in the ‘DBRep_IsoBuilder’ class, you are welcome to prepare iso curves using this algorithm or similar, it relates only to the linkage to TKDraw library.

There is another workaround to this crash, in additionally to described in the issue above (replace Tcl_Exit() to Tcl_Finalize()).

Code:
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS_Edge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS_Face.hxx>
#include <DBRep_IsoBuilder.hxx>

int main(int argc, char** argv)
{
    // build a topo_face
    ...
    TopoDS_Face top_face = BRepBuilderAPI_MakeFace(w);
    //
    DBRep_IsoBuilder IsoBuild(top_face, 100, 10);

    // finalization handler for Tcl/Tk thread
    HANDLE proc = GetCurrentProcess();
    TerminateProcess(proc, 0);
    //

    return 0;
}

The call is the same as OCCT use in callback (‘exitProc’) of TKDraw library. If you’re not preparing some additional processes in your application, may be it’s not so bad to terminate the current process at the end of the main…


By the way, thank you for preparing the minimum code and attaching it here. It helps quickly reproduce the problem.
 

jianbaoxia

CAD master
Hi @natalia ,
Thanks so much for your detailed and wonderful explanation.
I learn a lot in this forum.
It's my pleasure can let you repeat my problem through the simple demo.
Sincerely wish you well😃😃
 
Top