THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/12/2004 at 03:11, xxxxxxxx wrote:
Cinema 4D Version: 9
Platform: Windows ;
Language(s) : C++ ;
Now I've got a problem in memory leaking! I tried to make an object using ***Command Plugin. It's working ,but in the debug window it shows memory leaking. So I tried to release the memory after using the BaseObject and String and Vectors ( which are allocated using Alloc or bNew).
But when I try to do that, Cinema4D crash at all and close down. Here is my code:
BaseDocument *doc = GetActiveDocument();
BaseObject *obj = doc->GetActiveObject();
MessageDialog("No Selected Object!");
LONG cnt = pObj->GetPointCount();
BaseSelect *bs = pObj->GetPointS();
String *arrLocation1 =bNew String[cnt];
String *XLoc1=bNew String[cnt];
String *ZLoc1=bNew String[cnt];
String *arrNames1 = bNew String[j+1];//new(array, j+1);
BaseObject *ObjObj1 = BaseObject::Alloc(Ocube);
/****************************Here I use them***********************************************/
MessageDialog("Releasing the memory!");
//Releasing the memory
After the dialog box showing "Releasing the memory!" the program crash. Why? Did I choose the wrong plugin type? I look at the samples of Cinema4D and in their command plugins, I didn't find the creation of the objects.
Please, do a favour for me ... urgently.
I'm waiting ...
On 20/12/2004 at 07:06, xxxxxxxx wrote:
If you InsertXX() anything into a C4D Document, it is then OWNED by C4D. Freeing afterwards will crash C4D since your plugin no longer has ownership. If you want to free the memory, you must first Remove() it from the Document.
Memory management is all about ownership - who or what class owns the allocated memory and is thus responsible for its release.
On 21/12/2004 at 21:02, xxxxxxxx wrote:
Thank you so much, Robert. I'm gonna try it. And I also want to know the reason << why an object is not accessible after SendModelingCommand>>. Let's say ...
//mcd is ModelingCommandData
//Obj1 is Ocube BaseObject
The MessageDialog("NotNull") shows that Obj1 is not NULL. But when I try to use it , let's say , Obj1->SetPos(Vector(1.0,1.0,1.9));,
Cinema4D crash. So I must write Obj1=doc->SearchObject(vTempName); .
This code segment is in a loop. So when I try to make it loop (x) times, the C4DTrace shows that (x-1) block is leaked and each block is
40 bytes. Firstly I think it because of BaseContainer. So I leave out the BaseContainer variable completely and use it directly using
GetDataInstance() and not assigning to anything. But the leak is going on. bDelete is OK for now. I think the problem is totally based on
So I try using GetClone ( like the way in the sample program LiquidTool).
I declare ...........
outside the loop.
In the loop ....
is inserted. Then the above code segment I showed follows.
Outside the loop I release the Obj2 . No crash. But still leaking.
Maybe, my letter is complex , if you don't get me, do a favour for me and read it again,please.
Really thank you so much.
On 21/12/2004 at 22:54, xxxxxxxx wrote:
Well, Cinema 4D replaces the original object with the 'editable' one. SendModelingCommand(), in these cases, returns a pointer to the new object in mdc.results1. Obj1 doesn't 'exist' any more. Check my code to see what's happening:
cd.doc = doc;
cd.op = rootObj;
cd.mode = MDATA_CURRENTSTATETOOBJECT_INHERITANCE|MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION;
if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) throw ErrorException(ERROR_MODELINGCOMMAND, "Current State to Object");
// *** This is the new, replacement object
rootObj = cd.result1;
doc->InsertObject(rootObj, NULL, NULL, FALSE);
On 27/12/2004 at 00:22, xxxxxxxx wrote:
Thank you so much ... and very good is your explanation.
I get it. Sorry for my late reply. Internet connection is not so good in our company.
See again and happy new year.