debug out: memory corrupt / free-crash
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 27/09/2008 at 08:34, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 9
Platform: Windows ;
Language(s) : C++ ;---------
Hello fellow devsi have this strange crash with my paintonsurface plugin which i dont understand.
It only happens when i use the stacking feature to paint objects on top of other painted objects (stacking), and only if i stack so much that editor performance gets really choppy. if i use the feature only modestly everything is fine.
the crash seems to be due to freeing some temp object (scCopy),which is needed during the stacking process. Freeing works fine when i stack only modestly, and editor display is still fluid.
if i dont free, it doesnt crash anymore, but ofc i get memleaks, which is why i need the free.
here's the code snippet, freeing is at the bottom..
--------------
<CODE>
.
.
BaseObject* scCopy = NULL;
BaseObject* copy = NULL;
ModelingCommandData md1;
// init rayCollider with object to check ray collisions on
if(stackClones && mode==POS_MODE_OBJECT){
// make a copy of the object
scCopy = (BaseObject* )obj->GetClone(COPY_NO_ANIMATION,NULL);
scCopy->SetName("objCopy");
scCopy->SetPos(Vector(0,0,0)); scCopy->SetRot(Vector(0,0,0));
md1.op = scCopy; md1.doc = doc;
if(!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, md1)) return NULL;
BaseObject::Free(md1.op);
md1.op = static_cast<BaseObject*>(md1.result->GetIndex(0));
AtomArray::Free(md1.result);AtomArray::Free(md1.arr);
if(!SendModelingCommand(MCOMMAND_JOIN, md1)) return NULL;
copy = static_cast<BaseObject*>(md1.result->GetIndex(0));
BaseObject::Free(md1.op);AtomArray::Free(md1.result);AtomArray::Free(md1.arr);
.
.
.
.
// later temp objects from above get free'd, when they are not needed anymore
.
.
if(stackClones){
// free stuff not needed anymore, to prevent mem leaks
// ..
// unfortunately, if we use lots of stacking, cinema crashes bc of this
// maybe bc system is stressed too much when stacking heavily? editor fps is like <5 before crashing..
// if stress is less, no crashes happen..BaseObject::Free(scCopy);
}
.
.
[\CODE]i really cant see anything wrong with this, as it usually works, unless i stack too much..
strange thing is, in the R9 console, i get this:
(but not in R11 console, but R11 crashes too) :DebugOut:
C4D Trace Start...
Memory Start Corrupt
Memory Corrupt!
F:\work9.x\src\Richard\Genesis\ge_memory.cpp<950> : ALERTthe last line must be sth from a maxon dev, as i dont have drive F: ..
so could it be, that with the code everything is alright, and its just that my memory is faulty?
so that maybe when a certain address is reached, the crash happens ?thanks,
Daniel -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/09/2008 at 01:24, xxxxxxxx wrote:
Could it be that you forgot to free scCopy if CSTO fails?
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/09/2008 at 01:37, xxxxxxxx wrote:
yes i forgot that, thanks for the hint
i'll see if this changes anything, but shouldnt i have gotten mem leaks, if it failed and i didnt free it? -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/09/2008 at 02:08, xxxxxxxx wrote:
ok i free the object now also when sendmodellingcommand fails, but i still get the crash at the line where i free scCopy.
when i check in the debugger, scCopy looks ok at that time, its not null or anything, but some address in memory.
could it be that for some reason, that address is not the right address for the object anymore ?
this might sound silly, but is it possible that the adress got mixed up due to heavy load on the processor ?as mentioned before, the crash only happens under extreme conditions, when editor performance is really bad.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/10/2008 at 07:25, xxxxxxxx wrote:
ok i think i got it now.
Now i just check if copy is null before freeing, and also i got rid of one unneccessary copy (scCopy). the latter probably made the difference.>
\> BaseObject\* copy = NULL; \> ModelingCommandData md1; \> // init rayCollider with object to check ray collisions on \> if(stackClones && mode==SURFPAINT_MODE_OBJECT){ \> // get CSTO'd and joined copy \> copy = getPolyObject(obj,doc); \> copy->SetMl(copy->GetMln()); \> //copy->InsertAfter(obj); \> rc->Init(copy,TRUE); \> } \> else rc->Init(obj,TRUE); \> . \> . \> . \> if(stackClones){ \> if(copy!=NULL) BaseObject::Free(copy); \> } \>
greetings,
Daniel