Crash on Poly_Triangulation

This has already been submitted as a bug report.
When executing the OpenCascade code below, I always get a crash at the specific position when Poly_Triangulation returns the number of polygons.

The Boolean Cut operation is used on a cone and a cylinder. The apex of the cone lies on the surface of the cylinder - this could probably be a problem for the triangulation routine.

Please give me feedback if you know more about the error or a possible solution.

p.s. OCC version 4.0, Windows 2000.

Thank you very much in advance,
Hannes Kaufmann

TopoDS_Shape Shape1, Shape2;

// first Shape = Cylinder
gp_Pnt middlePoint = gp_Pnt(0.163459, -0.201837, 0.27078);
gp_Dir direction = gp_Dir(0.434193, 0.0224651, -0.100088);
gp_Ax2 Ax2 = gp_Ax2(middlePoint, direction);
Shape1 = BRepPrimAPI_MakeCylinder(Ax2, 0.0352593,0.446145);

// second Shape = Cone
gp_Pnt middlePoint = gp_Pnt(0.217953, -0.275273, 0.12121);
gp_Dir direction = gp_Dir(0.274833, 0.0887223, 0.110744);
gp_Ax2 Ax2 = gp_Ax2(middlePoint, direction);
Shape2 = BRepPrimAPI_MakeCone(Ax2, 0.0635114, 0, 0.309304);

TopoDS_Shape Shape = BRepAlgoAPI_Cut(Shape1, Shape2);

BRepMesh::Mesh(Shape, 1);

for(TopExp_Explorer ex(Shape,TopAbs_FACE); ex.More(); ex.Next())
{

TopoDS_Face F = TopoDS::Face(ex.Current());

TopLoc_Location L;

Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);

//--> crashes when executing next line

int NumNodes = facing->NbNodes(); // --> crashes here !!!

const TColgp_Array1OfPnt& NodesArray = facing->Nodes();

int NumTri = facing->NbTriangles();

const Poly_Array1OfTriangle& TriArray = facing->Triangles();
}

samuel's picture

Hi !
"
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);

//--> crashes when executing next line

int NumNodes = facing->NbNodes(); // --> crashes here !!!
"
Sometime facing is null !
so try this:

if(!facing .IsNull() )
{
int NumTri = facing->NbTriangles();

const Poly_Array1OfTriangle& TriArray = facing->Triangles();
}

and the triangulation is correct

Michael Gandyra's picture

I have no problem with it. It seems to me, that a value of 1 for the deflection in BRepMesh::Mesh is too big. Try to give it a value like 0.05 or similar and of course check for a Null Handle like Samuel proposed.

Regards,
Michael