access violation on TKBREP.dll

Hello, maybe I'm dumb, but I really can't understand this:

I'm creating a 4th order BSplineSurface, and everything goes fine (no Standard_ConstructionError is thrown after Geom_BSplineSurface construction).

Then I want to convert it to an AIS_Shape to display it, and I get an "Access Violation" error on TKBREP.DLL

Here it is the code:

//... arrays assignment code before..

try {

Handle(Geom_BSplineSurface) srf = new Geom_BSplineSurface (
arrPointsSurface, // control points double array
arrUKnots, // dimension U knots array
arrVKnots, // dimension V knots array
arrUMult, // dimension U multiplicity array
arrVMult, // dimension V multiplicity array
4,
4,
Standard_False, // not U periodic
Standard_False // not V periodic
);

// convert it to Geom_Surface, seems to go fine
Handle(Geom_Surface) aSurf = srf;

// MakeFace gives "Access Violation" on TKBREP.DLL!!!!
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aSurf);

// Display code which is not reached
Handle (AIS_Shape) BSShape = new AIS_Shape(aFace);
myAISContext->Display(BSShape);

} catch ( Standard_ConstructionError e ) {
//as I said, this code is never reached because the BSpline is correct
//...
}

Any ideas? Thanks

Francois Lauzon's picture

The only idea I have is to check where the exception is raised, this will help you see what's wrong... First link with the debug version of the Open Cascade library, then put break point on Standard_Failure constructor (I think there is two differents constructor), then look at the call stack and see where it was raised and why, by looking at all the differents variables you have and their values (null pointer, ...).
This is what I do everytime I have such a problem, and I usually find the problem quite fast that way.

Good Luck,
Francois.

Fabio Napodano's picture

Thanks Francois,
Yesterday I've started looking for the problem by using the code instead of the library (if anyone needs to know how to do it: simply add the needed cxx and ixx files to the project, and remove "STANDARD EXPORT" from the function you want to inspect in the hxx file), and the error is given on this line:

// from Brep_Builder.cxx, function BRep_Builder::NaturalRestriction(
// const TopoDS_Face& F, const Standard_Boolean N)const
(*((Handle(BRep_TFace)*) &F.TShape()))->NaturalRestriction(N);

Looks like TShape() does not return a valid pointer for some reason.

I will investigate this further.

I will also try your idea.