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();
Handle(BRepAdaptor_HCurve2d) HC2d2 = new BRepAdaptor_HCurve2d();
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 ())
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
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.