Cleaning up after me, Free(), where is the doc
-
On 10/02/2014 at 11:09, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13,14,15
Platform: Windows ;
Language(s) : C++ ;---------
Currently I have one issue that I only can solve by (perhaps) violating some Maxon guidelines on how to write proper plugins.My plugin has several helper objects, inserted into the document.
When the user removes, deletes, the tag, I of course want these helper objects to be removed too. But what if the user invokes an Undo command? Then the tag comes back - without helper objects.So - here it goes:
Question 1) Why is Init() called when I delete the tag? For what purpose?In the Free() method, I get a GelistNode* all right, as a function argument. But node->GetDocument() returns NULL. I need the document in order to add an Undo for the helper objects! Here I have perhaps violated the Maxon rules, by storing the doc as a global variable, at an earlier stage of the tag's life time, when the doc still was accessible. Now, this somehow works, but I feel it is not reliable.
Question 2) Is there a message / function that I have overlooked, where the tag is notified about it being removed, before the BaseDocument is over the horizon, out of reach?
How do you deal with this? If my tag is removed, there are in fact several operations I have to carry out, where I just need access to the document. BTW, I have no problems determining if Cinema 4D itself is closing down or not, because if, then the undo pointer in the doc is NULL, even if the doc itself still is hanging out there.
-
On 11/02/2014 at 04:50, xxxxxxxx wrote:
Instead of using Free() to store undos, maybe check for the message
MSG_DESCRIPTION_INITUNDO
or some other message that is consistent just before the tag is freed (in Message() override).Unfortunately, the API doesn't give you such control without some fiddling, if at all. You may want to store the helper objects (pointers) into an AtomArray associated with the tag so that you do not need the document. Of course, they may be freed before your tag Free() code is hit which would make the pointers stored in AtomArray possibly invalid by that time.
-
On 11/02/2014 at 08:47, xxxxxxxx wrote:
Hi, I haven't found any usable messages, for this purpose. On the other hand, after I found out that Init() also is called when the tag is being removed (who knows why), everything is getting much better, because then I can stay clear of the "false" Init(), and use only the real one.