Geom_Curve::DynamicType() throws exception

Hi guys,

using OpenCASCADE6.6.0 we run into a problem while converting a mesh. The following code results in the exception

"Unhandled exception at 0x00481b62 in OCCSample.exe: 0xC0000005: Access violation reading location 0xfefd0000."

void OCCConverter::ConvertToCurve(const TopoDS_Edge& _edge)
{
Standard_Real first, last;
BRep_Tool::Range(_edge,first,last);
Handle_Geom_Curve geomCurve = BRep_Tool::Curve(_edge, first, last);

if(geomCurve!=NULL)
{
Handle_Standard_Type type = geomCurve->DynamicType();
std::cerr DynamicType()->Name() }
...

However, most often this succeeds:

processing type Compound
Geom_BSplineCurve
...
Geom_BSplineCurve
*exception occurs*

Do you have an idea about what I am doing wrong?

Thank you very much in advance.

Francois Lauzon's picture

Hello,
It could be a number of thing. Usually it means that at one point you got a NULL point. From your source code it could be _edge, geomCurve or geomCurve->DynamicType().

Best way to solve this is to go step by step using the debugger.

Good luck,
Francois.

David Schaefer's picture

Hi François,

thank you very much for the answer.

_edge is a const TopoDS_Edge&, cannot be NULL.
geomCurve is checked for not being NULL.
geomCurve->DynamicType() throws the exception.

Stepping through this with the debugger only jumps to
myfile.cpp:geomCurve->DynamicType();
handle_geom_curve.hxx:DEFINE_STANDARD_HANDLE(Geom_Curve,Geom_Geometry)
handle_standard_transient.hxx: Standard_Transient* ControlAccess() const { return entity; }
handle_geom_curve.hxx:DEFINE_STANDARD_HANDLE(Geom_Curve,Geom_Geometry)
myfile.cpp:geomCurve->DynamicType();
*exception occurs*

So what may this be?

Francois Lauzon's picture

Hi David,

First off:
> _edge is a const TopoDS_Edge&, cannot be NULL.

This is not true, is you test _edge.IsNull() is could be NULL, even if you have a const TopoDS_Edge& because TopoDS_Edge is derived from TopoDS_Shape and TopoDS_Shape hold a reference to a pointer, a location and an orientation.

Also, I usually test for NULL pointer using the IsNull() method in OCC, never use the !=NULL so I'm not sure it is working that way. Try expanding the variable geomCurve in the debugger up until you see the entity variable from Handle_Standard_Transient to see if you could find a valid pointer value there.

So you could test for _edge.IsNull() and if it is good, check for geomCurve.IsNull().

Francois.

David Schaefer's picture

Hi François,

thank you for solving my problem. I wasnt aware of the IsNull() function and the reference inside the data structures.

The code
Handle_Geom_Curve geomCurve = BRep_Tool::Curve(_edge, first, last);
seems to return a null handle. The documentation for BRep_Tool::Curve says: "Returns the 3D curve of the edge. May be a Null handle", but not when a null handle is the result of the operation. I wonder how this can happen.

Francois Lauzon's picture

Hi David,
have a look at the manual modata.pdf, it is all explained there in details.

And for the _edge case, if the _edge is not NULL, this means you have at least a 3d curve or a 2d curve (curve on surface) or both. So in your case, if geomCurve is NULL you probably only have a 2d curve (use BRep_Tool::CurveOnSurface to retrieve it).

If you really need a 3d curve and only have a 2d curve, you could use ShapeFix_Edge::FixAddCurve3d, this will build a 3d curve for you based on your 2d curve.

Francois.

David Schaefer's picture

Hi François,

i wasnt aware that the really useable documentation comes with the non-document executable. Thank you for all your valuable tips.

Cheers,
David