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:
Cinema 4D Version: 8.206
Language(s) : C++ ;
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
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?
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);
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