ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

crash while delete an edge

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
geffrey.liu
1200 Views, 16 Replies

crash while delete an edge

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
}

16 REPLIES 16
Message 2 of 17
geffrey.liu
in reply to: geffrey.liu

does anyone know what's the problem?

thanks in advance.

 

PS: it works well in AutoCAD2010, but fail in later version.

Message 3 of 17
nick83
in reply to: geffrey.liu

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. )))

Message 4 of 17
geffrey.liu
in reply to: nick83

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;
}

Message 5 of 17
nick83
in reply to: geffrey.liu

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 )))

Message 6 of 17
maisoui
in reply to: nick83

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 *&?

--
Jonathan
Message 7 of 17
maisoui
in reply to: maisoui

Another adivce is to check the returns (AcBr::ErrorStatus) of the method...

--
Jonathan
Message 8 of 17
geffrey.liu
in reply to: maisoui

That's what I am puzzled. Why it can be deleted before.

Message 9 of 17
geffrey.liu
in reply to: maisoui

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);

 

Message 10 of 17
owenwengerd
in reply to: geffrey.liu

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".

--
Owen Wengerd
ManuSoft
Message 11 of 17
geffrey.liu
in reply to: owenwengerd

Hi, Owenwengerd, Thanks for your helpful reply.
I haven't used different heap and it works well in AutoCAD2010.
Message 12 of 17
nick83
in reply to: geffrey.liu

OMG, i've already told about the reason in my first post. COMPILER. i had a great quantity of old source code, that worked fine for AutoCAD 2000-2006, but, for example, in 2007 does nothing or crashes autocad, e.t.c. So, if the code was correct from the beginning it'll work fine for any autocad!!! (after compilation of course).
PS: some of "my" old code crashed autocad 2015, but everything was fine up to 2014. after modifications in VS2012, code works for 2010-2015 ))).
Message 13 of 17
geffrey.liu
in reply to: nick83

Owenengerd thinks that the caller should delete the memory from getcurve()
Message 14 of 17
owenwengerd
in reply to: geffrey.liu


@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?

--
Owen Wengerd
ManuSoft
Message 15 of 17
artc2
in reply to: geffrey.liu

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.

Message 16 of 17
geffrey.liu
in reply to: artc2

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)?

Message 17 of 17
artc2
in reply to: geffrey.liu

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost