Access violations in BRepLib.cxx

I have some access violations due to corrupt/uninitialized? geometry objects in BRepLib.cxx during (XDE) STEP import (Win64Bit, OCC 6.3.1-6.5.1, default import parameters). Unfortunately, I cannot share the STEP file causing this.
The related code is in BRepLib.cxx starting from line 1508:

Handle(BRepAdaptor_HCurve2d) HC2d1 = new BRepAdaptor_HCurve2d();
HC2d1->ChangeCurve2d().Initialize(E,F1);
if(couture) E.Orientation(TopAbs_REVERSED);
Handle(BRepAdaptor_HCurve2d) HC2d2 = new BRepAdaptor_HCurve2d();
HC2d2->ChangeCurve2d().Initialize(E,F2);

Adaptor3d_CurveOnSurface C1(HC2d1,HS1);
Adaptor3d_CurveOnSurface C2(HC2d2,HS2);

The Geom2dAdaptor_Curve in HC2d2 does not get initialized properly. This causes an access violation in the constructor of Adaptor3d_CurveOnSurface. I inserted the following code before Adaptor3d_CurveOnSurface to avoid the access violation:

if (HC2d1->Curve2d ().BSpline ().IsNull () || HC2d2->Curve2d ().BSpline ().IsNull ())
{
return Standard_False;
}

There is similar code in BRepLib.cxx starting from line 401:

Geom2dAdaptor_Curve AnAdaptor3dCurve2d (Curve2dPtr, f, l) ;
GeomAdaptor_Surface AnAdaptor3dSurface (SurfacePtr) ;

Curve2dPtr and SurfacePtr point to invalid geometry which causes an invalid constructed Geom2dAdaptor_Curve and an access violation in GeomAdaptor_Surface constructor.

The defect geometry objects causing this are probably generated during ShapeHealing, since the access violations do not appear if I set all ShapeFix parameters in the resource STEP file to 0.

I don´t know if this is a bug or what I should do to prevent at least the crash in my application. If you have suggestions they are very welcome. Even if I insert geometry checks in BRepLib I don´t know how many similar places are there in the OCC code that could also cause a crash. Would it be possible to guarantee correct geometry objects by inserting something like

Standard_NullObject::Raise("BRepAdaptor_Curve::No geometry");

or similar in all ::Load ::Initialize methods and geometry constructors? Or at least an easy isValid () check on geometry objects?

Sorry for this vague post. I am not that deep in the OCC code and can´t really say if this is a bug and where exactly the code is that needs to be fixed. All your comments are welcome.

Forum supervisor's picture

Hello, Markus,
I would like to inform you that this problem has been checked and reproduced. This is really a bug. Our Bugtracker is currently being maintained, but as soon as it is available again we will register this problem as a bug and I will post the bug ID here, in this topic. We will try to fix the problem in future OCCT releases. You will be able to see later if the issue is resolved by checking the references to the specified ID in OCCT Release Notes. The analysis of this issue will take some time depending on our technical capability and availability of resources.
Regards.

Forum supervisor's picture

Hello, Markus, this bug has been registered with ID = 0022690

P G's picture

closing remark for 22690 is :

This problem is likely to be fixed by #22789, to be checked after the release of OCCT 6.5.3

is it resolved ?

Forum supervisor's picture

Dear PG,
Yes.
FSR