Change variables when closing tag



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 16/04/2008 at 10:01, xxxxxxxx wrote:

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

    ---------
    Here's another problem: I have to set some data in the object's containers when the tag is closed. Right now this is done by the following source code:

    > <code>
    > void MoCap::SetBackIDs (){
    >
    >      BaseDocument *doc = GetActiveDocument();
    >      GePrint ("doc");
    >      BaseTag *tag = doc->GetActiveTag();
    >      GePrint ("tag");
    >      BaseObject *op = doc->GetFirstObject();
    >      GePrint ("op");
    >      BaseObject *current;
    >      GePrint ("current");
    >      BaseContainer *opContainer = op->GetDataInstance();
    >      GePrint ("opContainer");
    >      
    >      while (op!= NULL){
    >           GePrint ("while");
    >      opContainer = op->GetDataInstance();
    >      opContainer->SetBool (DESC_USED, FALSE);
    >      opContainer->SetLong (DESC_JOINT_ID, 0);
    >      current = op->GetDown();
    >      if (current == NULL)
    >           current = op->GetNext();
    >      if (current == NULL)
    >           current = op->GetUp()->GetNext();
    >      op = current;
    >      }
    >
    > }
    > </code>

    while the method SetBackIDs is called within the destructor of my Plugin:

    > <code>
    > ~MoCap(void) {SetBackIDs();}
    > </code>

    I'm sure that this is not very clever. It works, but when finishing Cinema the destructor is called again and only finds the document. When searching for the active tag or the first object, Cinema crashes. How do I solve this one?

    Thx



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 16/04/2008 at 10:32, xxxxxxxx wrote:

    1. Call SetBackIDs() in the tag's Free() method. Technically, one should never use a class's destructor to do 'work' - only to release memory owned by the class.

    2. Verify pointers in SetBackIDs() and Cinema 4D won't crash. ETA: For instance, you don't check 'op' until after calling op->GetDataInstance() - do it before this.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/04/2008 at 05:47, xxxxxxxx wrote:

    Hi, thx. The Free()method seems indeed the better way.

    Still there is the problem of crashing. How do I exactly verify the pointers? Something like
         if (!doc->GetFirstObject())return;
    doesn't seem to work.


Log in to reply