On 22/03/2013 at 10:05, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R13
Platform: Windows ;
Language(s) : C++ ;
---------
Hi,
I've written a kind of cloner object using GetVirtualObjects. I alloc instances of the original object and group it under a null. I'm now wondering if this will produce a memory leak, since the objects will never be freed, f.ex. if the user switches off the generator.
Additional, I would kindly ask you, if you think, this is the best method due to performance. It may produce thousends of clones.
BaseObject *IMVertec::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
{
BaseDocument *doc = hh->GetDocument();
BaseContainer *bc = op->GetDataInstance(); // Daten-Container
BaseObject *tp = op->GetDown(); // Tracker-Masterobjekt
if (!tp || !bc->GetBool(INIT))
{
op->SetDeformMode(FALSE); // Objekt ausschalten
bc->SetBool(INIT, FALSE);
return NULL;
}
Bool dirty = FALSE;
BaseObject *pp = op->GetAndCheckHierarchyClone(hh, tp, HIERARCHYCLONEFLAGS_ASIS, &dirty;, NULL, TRUE);
if (!dirty) return pp;
if (!pp) return NULL;
// Tracker-Klone erzeugen und auf dem Grid positionieren
AutoAlloc<BaseLink> link;
BaseObject *gp = bc->GetObjectLink(IMV_GRID_LINK, doc);
Matrix mg = gp->GetMg();
BaseObject *mp = BaseObject::Alloc(Onull);
if (!mp || !link) goto Error;
link->SetLink(tp);
LONG i, pcnt = ToPoly(gp)->GetPointCount();
const Vector *pAdr = ToPoly(gp)->GetPointR();
for (i=0; i<pcnt; i++)
{
BaseObject *cp = BaseObject::Alloc(Oinstance);
if (!cp) goto Error;
cp->SetParameter(DescLevel(INSTANCEOBJECT_LINK), GeData(link), DESCFLAGS_SET_0);
cp->SetRelPos(pAdr[i] * mg);
cp->InsertUnderLast(mp);
}
return mp;
Error:
blDelete(pp);
blDelete(mp);
return NULL;
}
Maybe, the source code of the C4D cloner object is available somewhere?
Thanks for your assistance.