Dear all,
I am writing you because I am having a problem with the OCC DLLs. I have prepared a small example which shows the problem.
The problem is that when I compile and run my example in Release x64 configuration, the creation of a BRepOffsetAPI_MakePipe object makes the application crash because of a crash in the TKBRep.dll due to access reading location 0xFFFFFFFFFFFF. What is a bit puzzling as well is that if the code is compiled in Release Win32, everything works fine and the result is correct. Hereafter I describe the process I am following to compile the library and the code I have written. Please, note that the objects I create (i.e. cylinder, faces) are created using the classes of OCC. I am currently using the version 6.8.0 but I have observed the same problem with version 6.9.0. For this reason, I am prone to think the problem is in the code I am writing.
Process to install OCC for Win32 and x64 configuration.
1. Download the OCC 6.8.0 Windows Installer and install the library. This will result in the installed Win32 libraries and DLLs.
2. Open the OCC.sln in Visual Studio 2013 and compile the packages needed for the example in the Release x64 configuration. This will create libraries and DLLs in the win64 folder within the installation folder.
Example code:
void constructWires(gp_Pnt pointZero, gp_Pnt pointOne,
TopoDS_Wire& circular, TopoDS_Wire& straight,
TopoDS_Face& faceCircular)
{
BRepBuilderAPI_MakeEdge edgeS(pointZero, pointOne);
edgeS.Build(); edgeS.Check();
BRepBuilderAPI_MakeWire wireS(edgeS.Edge());
wireS.Build(); wireS.Check();
straight = wireS.Wire();
gp_Vec vec(pointZero.X() - pointOne.X(), pointZero.Y() - pointOne.Y(), pointZero.Z() - pointOne.Z());
gp_Dir dir = vec.Normalized();
gp_Ax2 ax(pointZero, dir);
Handle(Geom_Circle) circle = new Geom_Circle(ax, 50.0);
BRepBuilderAPI_MakeEdge edgeC(circle);
edgeC.Build(); edgeC.Check();
BRepBuilderAPI_MakeWire wireC(edgeC.Edge());
wireC.Build(); wireC.Check();
circular = wireC.Wire();
// Face One creation
gp_Pln plane(pointZero, dir);
BRepBuilderAPI_MakeFace faceCreated(plane, circular, Standard_True);
faceCreated.Build(); faceCreated.Check();
faceCircular = faceCreated.Face();
}
void buildSolid(TopoDS_Wire& circ, TopoDS_Wire& straight, TopoDS_Solid& solid, TopoDS_Face faceToSweep)
{
//BRepTools::Write(straight, "straight.brep");
//BRepTools::Write(circ, "circ.brep");
// In this example, the shape is a cylinder but the class
// BRepOffsetAPI_MakePipe because the wire representing the
// axis of the cylinder might be composed of different edges
// properly alinged.
// This line generates the TKBRep.dll failure trying to access
// 0xFFFFFFFFFF location.
BRepOffsetAPI_MakePipe shell(straight, faceToSweep);
shell.Build();
shell.Check();
//shell.MakeSolid();
TopExp_Explorer solidInS(shell.Shape(), TopAbs_SOLID);
if (!solidInS.More())
{
std::cout
return;
}
solid = TopoDS::Solid( solidInS.Current() ) ;
BRepTools::Write(solid, "solid.brep");
}
void cutFace(TopoDS_Shape solid, TopoDS_Shape face, TopoDS_Shape& shape)
{
BRepTools::Write(face, "faceInCut.brep");
BRepTools::Write(solid, "solidInCut.brep");
TopoDS_Shape faceToCut(face);
TopoDS_Shape solidToCut(solid);
BRepAlgoAPI_Cut cut(faceToCut, solidToCut);
cut.Build(); cut.Check();
shape = cut.Shape();
}
TopoDS_Face constructSquareFace()
{
gp_Pnt pOne(-100.0, 75.0, 0.0);
gp_Pnt pTwo(-100.0, -75.0, 0.0);
gp_Pnt pThree(200.0, -75.0, 0.0);
gp_Pnt pFour(200.0, 75.0, 0.0);
BRepBuilderAPI_MakeEdge edgeOne(pOne, pTwo);
BRepBuilderAPI_MakeEdge edgeTwo(pTwo, pThree);
BRepBuilderAPI_MakeEdge edgeThree(pThree, pFour);
BRepBuilderAPI_MakeEdge edgeFour(pFour, pOne);
BRepBuilderAPI_MakeWire wire(edgeOne.Edge(), edgeTwo.Edge(), edgeThree.Edge(), edgeFour.Edge());
wire.Build(); wire.Check();
BRepBuilderAPI_MakeFace sqFace(wire.Wire(), Standard_True);
sqFace.Build(); sqFace.Check();
return sqFace.Face();
}
void testCrash(void)
{
gp_Pnt pointZero(0.0, 0.0, 0.0);
gp_Pnt pointOne(100.0, 0.0, 0.0);
TopoDS_Wire circular;
TopoDS_Wire straight;
TopoDS_Face faceCircular;
// This method creates a circular face which then will be swept
// along the straight wire which represents the axis of the cylinder.
constructWires(pointZero, pointOne, circular, straight, faceCircular);
TopoDS_Solid solid;
// This method constructs the solid, i.e. cylinder, used to cut.
buildSolid(circular, straight, solid, faceCircular);
BRepTools::Write(solid, "solid.brep");
// This is the face which will be cut.
TopoDS_Face faceToCut = constructSquareFace();
BRepTools::Write(faceToCut, "sqFace.brep");
// Perform cut operation.
TopoDS_Shape shape;
cutFace(solid, faceToCut, shape);
BRepTools::Write(shape, "shape.brep");
std::cout
}
int _tmain(int argc, _TCHAR* argv[])
{
std::cout
testCrash();
std::cout
return 0;
}
It seems to me that the code is correct and there is not any ambiguous parameters declarations in the definitions of the functions.
Could anyone point me to the right direction, please?
Any help is very much appreciated.
Kind regards,
Author