GetLink / Crash when deleting object



  • On 12/05/2013 at 12:32, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   r14 
    Platform:      
    Language(s) :     C++  ;

    ---------
    Hi, I am facing a problem which I dont understand..
    this is my code to get a linked object:

    ipCustomObject = bc->GetLink(IP_CUSTOM_OBJECT,doc);
    if (!ipCustomObject) return FALSE;
    ...
    

    I was thinking that this prevents further problems when the linked object is removed by the user, but it doesnt. Can anyone point out whats wrong?

    later on in the code i use the linked object to create an instance. everything works well until the user deletes the object.

      
    innerPillar = BaseObject::Alloc(Oinstance);
    innerPillar->SetParameter(DescID(INSTANCEOBJECT_LINK),GeData(ipCustomObject),DESCFLAGS_SET_0);
    innerPillar->InsertUnder(main);
    

    cheers,
    Ello



  • On 12/05/2013 at 16:55, xxxxxxxx wrote:

    I would simply get the linked object at those points where you need to use it instead of storing it as a class member and hoping for the best.  If the user deletes the object or clears the link, you will get a NULL for GetLink() when you do need to use it and thereby avoid the crashes by using the condition at that point.  Also, you can use GetObjectLink() to avoid casting.



  • On 13/05/2013 at 00:12, xxxxxxxx wrote:

    thank you, Robert. now it works.. but what about performance as it looks a bit strange like this now:

    if (bc->GetObjectLink(IP_CUSTOM_OBJECT,doc)) {
    innerPillar = BaseObject::Alloc(Oinstance);
    innerPillar->SetParameter(DescID(INSTANCEOBJECT_LINK),GeData(ToPoly((PolygonObject* )(bc->GetObjectLink(IP_CUSTOM_OBJECT,doc)))),DESCFLAGS_SET_0);
    innerPillar = ((BaseObject* )ToPoly((PolygonObject* )(bc->GetObjectLink(IP_CUSTOM_OBJECT,doc))))->GetRad();
    ...
    

    maybe i need to get the parameters at another stage? now i am doing it like this:

    Bool myPlugin::Message(GeListNode *node, LONG type, void *t_data)
    {
    	if (type==MSG_DESCRIPTION_VALIDATE || type==MSG_FILTER)
    	{
    		BaseObject *op = (BaseObject* )node;
    		readParameters(op);
    	}
    	return TRUE;
    }
    


  • On 13/05/2013 at 05:29, xxxxxxxx wrote:

    Do it like this:

    PolygonObject* ipCustomObject =    ToPoly(bc->GetObjectLink(IP_CUSTOM_OBJECT,doc));  
    if (!(ipCustomObject && ipCustomObject->IsInstanceOf(Opolygon)))    return FALSE;  
    innerPillar = BaseObject::Alloc(Oinstance);  
    if (!innerPillar) return FALSE;  
    innerPillar->SetParameter(DescID(INSTANCEOBJECT_LINK),GeData(ipCustomObject),DESCFLAGS_SET_0);  
    innerPillar = ipCustomObject->GetRad(); // ????
    

    Not sure what you are doing in the last line.



  • On 13/05/2013 at 09:20, xxxxxxxx wrote:

    thank you for your help :)


Log in to reply