On 28/02/2016 at 20:47, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C++ ;
---------
Hi Folks,
I have an object plugin that's holding some documents in memory. There's an option for the user to 'edit' the document by making it the current working doc. I'm doing this with the following function:
bool MyPlugin_Object::Library_EditDoc(int id)
{
GePrint("Library_EditDoc(" + LongToString(id) + ") called..");
if(id > NULL && id < Library.size())
{
if(Library[id].Doc != nullptr)
{
BaseObject *obj = BaseObject::Alloc(ID_MYPLUGIN_OBJECT);
MyPlugin_Object *plug = (MyPlugin_Object* )obj;
plug->Set_EditDocumentFlag(TRUE);
BaseDocument *doc = Library[id].Doc;
GePrint("pre insert flag: " + LongToString(plug->GetEditDocumentFlag())); // OK
doc->InsertObject(obj,nullptr,nullptr,FALSE);
GePrint("post insert flag: " + LongToString(plug->GetEditDocumentFlag())); // WRONG VALUE
InsertBaseDocument(doc);
SetActiveDocument(doc);
return TRUE;
}
GePrint("Reference is nullptr..");
return FALSE;
}
GePrint("id out of range, returning");
return FALSE;
}
The issue I'm having is that when I insert the object using doc->InsertObject(...) the flag changes (and often returns a value of 144). It's a private member bool. I've tried a few variations of CopyTo() but neither seem to make any difference. Examples below.
Bool MyPlugin_Object::CopyTo(NodeData* dest,GeListNode* snode,GeListNode* dnode,COPYFLAGS flags,AliasTrans* trn)
{
MyPlugin_Object *plug_dest = (MyPlugin_Object* )dest;
// EXAMPLE 1:
plug_dest->Set_EditDocumentFlag(EditDocument);
// EXAMPLE 2:
plug_dest->EditDocument = EditDocument
return TRUE;
}
Both ways build fine. I've tried debugging the code, and depending on a few ways I make the Library_EditDoc() function I either get a spinning wheel, or it gets pulled up with no code to debug. It does go through and becomes the active working doc at times, but the flag is wrong. I've gone around the place with this, making clones of the doc and inserting into them instead. But I always get an error. It always seems to happen when using InsertObject(), or something related to this it seems.
What might be causing this, or where am I going wrong here? Cheers,
WP.