void f( AcBrEdge *pedge ){
AcGeCurve3d *edge ;
AcGeInterval interval ;
AcGePoint3d start,end ;
pedge->getCurve(edge) ;
edge->getInterval(interval,start,end) ;
double s_parm=interval.lowerBound() ;
double e_parm=interval.upperBound() ;
int ndiv=(int)(edge->length(s_parm,e_parm)/min_geom_size_G + 1) ;
AcGeLine3d line ;
if( edge->isLinear(line) ){
.....
}else{
.....
}
delete edge; // crash here
}
Solved! Go to Solution.
Solved by maisoui. Go to Solution.
does anyone know what's the problem?
thanks in advance.
PS: it works well in AutoCAD2010, but fail in later version.
looks like you have to comment delete edge;, because you don't create it.
about earlier versions can say, that compiler is different from VS2008, so it may crash.
the main rule is to delete everything you've created and do not touch anything else. )))
Thanks for your reply. However, there is a similar delete in brsample of arx
static AcBr::ErrorStatus
brepDumpDown(const AcBrBrep& brepEntity)
{
......
AcGeCurve3d* curveGeometry = NULL;
AcGeCurve3d* nativeGeometry = NULL;
returnValue = getNativeOrientedCurve(loopEdgeTrav, curveGeometry, nativeGeometry);
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in getNativeOrientedCurve:"));
errorReport(returnValue);
delete curveGeometry;
delete nativeGeometry;
return returnValue;
.......
}
the function called is following:
AcBr::ErrorStatus
getNativeOrientedCurve(const AcBrLoopEdgeTraverser& loopEdge,
AcGeCurve3d*& curveGeometry,
AcGeCurve3d*& nativeGeometry)
{
AcBr::ErrorStatus returnValue = loopEdge.getOrientedCurve(curveGeometry);
if (returnValue != AcBr::eOk) {
acutPrintf(ACRX_T("\n Error in AcBrLoopEdgeTraverser::getOrientedCurve:"));
errorReport(returnValue);
return returnValue;
}
if (curveGeometry == NULL) {
acutPrintf(ACRX_T("\n getNativeOrientedCurve: external 3d curve is undefined\n"));
returnValue = AcBr::eMissingGeometry;
return returnValue;
}
if (curveGeometry->type() != kExternalCurve3d) {
acutPrintf(ACRX_T("\n getNativeOrientedCurve: curve is not an external 3d curve\n"));
returnValue = AcBr::eMissingGeometry;
return returnValue;
}
if (!((AcGeExternalCurve3d*)curveGeometry)->isDefined()) {
acutPrintf(ACRX_T("\n getNativeOrientedCurve: external 3d curve is undefined\n"));
returnValue = AcBr::eMissingGeometry;
return returnValue;
}
if (!((AcGeExternalCurve3d*)curveGeometry)->isNativeCurve(nativeGeometry)
|| (nativeGeometry == NULL)) {
acutPrintf(ACRX_T("\n getNativeOrientedCurve: native 3d curve is undefined\n"));
returnValue = AcBr::eMissingGeometry;
return returnValue;
}
return returnValue;
}
try to follow the full usage of an variable in the brep sample project and you'll find something like pEnt = new AcBrBrep();
in this case you MUST delete your variable and free the memory. but in your code i can't see any creation. so, delete is just for program crash )))
I will not be as categorical as nick83, even if as a general rule he's right. My advice is to refer to the ARX documentation. For the method getCurve, it's not specified that you are responsible to free up the momory (no sentence like this : The caller of this function is responsible for allocating and de-allocating the memory). But, why it worked in ARX 2010 and why argument is passed by reference *&?
An example of arx shows that the following function feed back "curveGeometry" which needs to delete afterwards. However, in arx document, there is No warning such as "the caller is responsible for allocating and de-allocating the memory"
AcBr::ErrorStatus returnValue = loopEdge.getOrientedCurve(curveGeometry);
You have not said what exactly you mean by "crash here". I think the API was designed for the caller to delete the returned memory. If your delete uses a different heap than the heap used to allocate the object, this would indicate a likely bug -- either your code is not using the expected CRT heap (i.e. CRT linked statically instead of dynamic), or the API is using the wrong heap under the hood. But you should start by identifying the problem more precisely rather than just "crash here".
@geffrey.liu wrote:
Hi, Owenwengerd, Thanks for your helpful reply.
I haven't used different heap and it works well in AutoCAD2010.
What technique did you use to verify that you use the same heap?
Geffrey,
Perhaps I missed it, but I don't think you mentioned which version of AutoCAD you are working with. If it's the 2015 version, this could be a bug. The underlaying modeler was changed in AutoCAD 2015 and there were bugs with brep. Several of the bugs have been fixed in the service packs, so if you haven't already done so, you might want to check to see if this was one of them. If it wasn't fixed, then if you can provide the source for a full sample app as well as a drawing and steps to follow to reproduce the problem, I'll take a look and see what's going on.
Hi artc2, I am moving my code from AutoCAD2010 to AutoCAD 2012 and from win32 to win64.
is it indeed the caller's resposibility to release the memory of "edge" after writing pedge->getCurve(edge)?
Yes, it is the caller's responsibility to delete the AcGeCurve returned by getCurve. The function doesn't set the passed in pointer to NULL if an error occurs, so you should check the return status to be sure the function is successful before deleting otherwise you might end up corrupting random memory with the delete.