Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    GetLink / Crash when deleting object

    SDK Help
    0
    5
    536
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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;
          }
          
          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

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

              thank you for your help 🙂

              1 Reply Last reply Reply Quote 0
              • First post
                Last post