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
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Couple CopyTo questions

    Scheduled Pinned Locked Moved SDK Help
    3 Posts 0 Posters 247 Views
    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 Offline
      Helper
      last edited by

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

      On 30/12/2004 at 08:24, xxxxxxxx wrote:

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

      ---------
      Hello everybody,

      I have two questions, the one is probably a general c++ question so I apologize in advanced.

      I am designing a TagPlugin, but I am getting a strange behaviour when I copy an object with my tag plugin attached to it.

      I have a Vector member array that holds the original points of a spline before I modify them (my plugin heavily changes the points of a spline). I keep a copy of the original point positions so I can always revert back to the original spline.
      To make sure the renderer can 'see' this array, I copy it in the CopyTo method:

        
      Bool MyTagPlugin::CopyTo(NodeData *dest, GeListNode *snode, GeListNode *dnode, LONG flags, AliasTrans *trn)  
      {  
      ((MyTagPlugin* )dest)->OriginalPoints = this->OriginalPoints;  
      // And few more arrays  
      return NodeData::CopyTo(dest,snode,dnode,flags,trn);  
      }  
      

      My problem occurs when I copy an object that is using my tag. When I modify the points of the new object, the points on the other object are being modified too!
      I'm guessing that in the CopyTo method, array in the dest node is pointing to the array in 'this'. So when modifing either objects, causes both objects to change.
      If thats it, how do I fix it?

      Not much of a problem and I'm not sure if supposed to work like this but every frame (when my plugin executes), the CopyTo method is called. Is that by design?

      Thanks

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

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

        On 30/12/2004 at 09:31, xxxxxxxx wrote:

        1. Well, of course. You are just pointing the destination pointer to the source pointer. They now both point to the same memory. You need to allocate (GeAlloc()) a duplicate array for the destination and copy the source's data to it using CopyMem() or similar.

        Here's a CopyTo for one of my TagPlugins:

          
        // Copy data to copied PluginTag  
        Bool AVMTag::CopyTo(NodeData* dest, GeListNode* snode, GeListNode* dnode, LONG flags, AliasTrans* trn)  
        {  
             LONG avSize = sizeof(Bytef)*((BaseTag* )snode)->GetDataInstance()->GetLong(AVMTAG_AVMAP_COMPRESS);  
             if (!(((AVMTag* )dest)->avmapC = (Bytef* )GeAlloc(avSize))) throw ErrorException(ERROR_MEMORY, "AVMTag.CopyTo.adest->avmap");  
             CopyMem(avmapC, ((AVMTag* )dest)->avmapC, avSize);  
             return TRUE;  
        }  
        

        Robert

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

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

          On 30/12/2004 at 09:47, xxxxxxxx wrote:

          Thanks kuroyume0161, it was only as I was typing it up that I realized what I had done.
          It works a treat now 🙂

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