Memory Problem when using BRepOffsetAPI_ThruSections

Hi at all...
I´ve some problems when using the functionality of BRepOffsetAPI_ThruSections. What I do...

-define the BRepOffset_ThruSections object
-generate some closed splines (the outline equals a circle/the number of controlpoints is equal)
-make a wire form these splines BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(spline[i])))
and add it to the BRepOffset_ThruSections object using the addwire function
-run the build function from the BRepOffset_ThruSections object

It´s curious because the last step SOMETIMES fails with an AccessViolation exception. (I can quarantee that i didnt change the code during my tests | the splines are valid and the objects generated for the test have always the same values).
I tried to deactivate the optimization of the memory manager but that didn´t helped. Has someone a trick for me or has someone made the same experiences????
Thx in advance

StefanKunze's picture

Some additional informations...
I figured out that the problem appears when the number of sections is "relativ" high. When I use 5 sections the algorithm works to 99% percent. But when I use 15 sections use problems appears to 50% percent.

I tried to make use of the error handling mechanism but they didn´t catch the error. I quess it´s a memory problem but I´m not sure how i can prove it???

Any hints?????
Thx in advance

StefanKunze's picture

OK I was asked to send some more specific code... Here it is (its just some copy and paste but it produces the problems... sorry for the bad formation)

void SimpleTest(Handle_AIS_InteractiveContext pAISContext, int pBSplineAnz)
{
try
{
OCC_CATCH_SIGNALS

Handle (Geom_BSplineCurve)* lHandleUnconformBSplines = new Handle (Geom_BSplineCurve)[pBSplineAnz];
Handle (AIS_Shape) lHandleOrginalSurfaceShape;

BRepOffsetAPI_ThruSections lOrginalSurface = BRepOffsetAPI_ThruSections(Standard_False,Standard_True);
lOrginalSurface.CheckCompatibility(Standard_True);

int numberOfControlPoints = 4;
int minMainAxDistance = 100;
int maxRandomDistance = 25;
double zDistance = 20.0;
Standard_Real angle = 360/(numberOfControlPoints);
Standard_Real startAngle = 360;
Standard_Real currentangle;

// generate a nonconform OrginalSurface
for (int i = 0; i < (pBSplineAnz);i++)
{
Handle (TColgp_HArray1OfPnt) mHandlePoints = new TColgp_HArray1OfPnt(1,numberOfControlPoints);
Handle (Geom_BSplineCurve) mHandleBSpline;
startAngle = 0; //fmod((double)rand(),360);

for (int x = mHandlePoints->Lower(); x<= (mHandlePoints->Upper()); x++)
{
currentangle = fmod(startAngle+angle*(x-mHandlePoints->Lower()),360);
currentPnt =
gp_Pnt( sin_d(currentangle)*(minMainAxDistance+(rand()%maxRandomDistance)),
cos_d(currentangle)*(minMainAxDistance+(rand()%maxRandomDistance)),
zDistance*i);
mHandlePoints->SetValue(x,currentPnt);
}

if (mHandlePoints->Length()>0)
{
GeomAPI_Interpolate lSplineInterpolation(mHandlePoints, Standard_True, Precision::Approximation());
lSplineInterpolation.Perform();
while (!lSplineInterpolation.IsDone()) {}

mHandleBSpline = lSplineInterpolation.Curve();
lHandleUnconformBSplines[i] = mHandleBSpline;
}
}

// create OrignalSurface from the now conform BSplines
for (int i = 0; i < pBSplineAnz;i++)
{
if (!lHandleUnconformBSplines[i].IsNull())
lOrginalSurface.AddWire(BRepBuilderAPI_MakeWire(
BrepBuilderAPI_MakeEdge(lHandleUnconformBSplines[i])
));
}

lOrginalSurface.Build();
while (!lOrginalSurface.IsDone()){}
lHandleOrginalSurfaceShape = new AIS_Shape(lOrginalSurface.Shape());

// show the OrginalSurface
pAISContext->SetDisplayMode(lHandleOrginalSurfaceShape,1);
pAISContext->Display(lHandleOrginalSurfaceShape,Standard_True);

}
catch (Standard_Failure)
{
Handle (Standard_Failure) lErrorHandle = Standard_Failure::Caught();
Standard_CString lErrorMessage = lErrorHandle->GetMessageString();
}
}

Call this function multiple times to produce the error f.e. with SimpleTest(myViewer3D->GetAISContext(),25+rand()%50)

If someone can reproduce the error please write it here. Thx in advance

StefanKunze's picture

I figured out that the problem only occures when the controlpoints of the correspondening bsplines HAVE NOT the same x|y values. Or in other words when I translate one bspline along an axis and connect some sampled bsplines - the alogithm works very fine.

So I quess its not a problem with the memory... I think it´s problem with the calculations in the BRepOffsetAPI_ThruSections. Can someone please confirm my assumption.
(I set the parameter isRuled to false.... which - in my eyes - should simplify the calculations)

StefanKunze's picture

Ok.... problem solved.
This problem appeared because the continuity was set to GeomAbs_C2 OR the Periodic Flag was to true. These restrictions were sometimes to "heavy" for the building of the faces. I quess the algorithm tried to build the faces with C2 continuity and that was sometimes not possible.

In my eyes there should be the possibility to set the continuity in the BRepOffsetAPI_ThruSections class. By the way.... what continuity is set when I use the BRepOffsetAPI_ThruSections class with circles or other primitives...

Nevertheless... thx

Steven Diehl's picture

Hi Stefan,

I am experiencing the exact same phenomenon with an almost identical code to yours (7x periodic spline -> edge -> wire -> BRepOffsetAPI_ThruSections)... BRepOffsetAPI_ThruSections fails essentially randomly. When I increase the number of points in my spline I can get the same code to work... sometimes also by decreasing the number.

0x7ff02c89c82f : Standard_ConstructionError: Geom_BSplineSurface::InsertUKnots

Could you provide a code snippet that changes the Continuity of your splines?

Does anyone know if this "feature" is fixed in the new "minor" release that is not available for the public. The release notes claim improvements to the ThruSections algorithm from their new AppDef_TheVariational algorithm.

This is such a showstopper for me that any improvement to this function might perhaps warrant purchasing the new release...

Thanks for the help,
Steven