Cannot access BaseDocument in Free() method
-
On 08/08/2013 at 04:28, xxxxxxxx wrote:
Lo and behold - I found a solution!!
void MyTag::Free(GeListNode* node) { \> if(__HelperObject) \> \> { \> \> __BaseDocument->AddUndo(UNDOTYPE_DELETE, __HelperObject); \> \> __HelperObject->Remove(); \> \> } }
This works like magic! I have stored __BaseDocument at an earlier stage of the tag's life cycle, now it comes in handy, since node->GetDocument() returns NULL.
And - even more interesting, it seems that the Free() method is already "inside" a doc->StartUnd() .. doc->EndUndo().So when the user manually deletes the tag, and then invokes undo, the tag, and the helper object, reappears!!
So now all is just fine, only one issue remains - I cannot get hold of the BaseDocument inside the Free() method. -
On 08/08/2013 at 04:49, xxxxxxxx wrote:
Just one question, why do you use double underscore (_ _) in variable names?
In C++ this is reserved for implementation. (like __declspec, __forceinline ...) -
On 08/08/2013 at 04:56, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Just one question, why do you use double underscore (_ _) in variable names?
See my signature
-
On 08/08/2013 at 04:58, xxxxxxxx wrote:
I'd chose a more elegant solution. It is quite possible that your Helper Object has been removed by
someone (user, module, whatever) and removing the Helper Object in that case can lead to a
crash.You can create an invisible tag sitting on the helper object. This tag should check if _your tag_
still exists, and if it does not, it can remove the object. (Choose to do this in a Message() calle since
scene modifications in TagData::Execute() or similar methods is not recommended by MAXON).Best,
-Niklas -
On 08/08/2013 at 05:10, xxxxxxxx wrote:
Originally posted by xxxxxxxx
What is wrong is that doc is NULL. That is the very reason I started this thread.
My point was why are you using such a convoluted method to get the document, but hey, just carry on.
To answer your question it appears that once Free() is called, the node has been removed from the document and therefore GetDocument() will always return null.
-
On 08/08/2013 at 05:31, xxxxxxxx wrote:
Originally posted by xxxxxxxx
My point was why are you using such a convoluted method to get the document, but hey, just carry on.
Sorry about that, did not mean to be rude. I overlooked the direct method, I am using your code now.
Originally posted by xxxxxxxx
To answer your question it appears that once Free() is called, the node has been removed from the document and therefore GetDocument() will always return null.
Ok, that seems to be correct! Nevertheless, storing the document as a variable seems to work just fine.
-
On 08/08/2013 at 05:33, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I'd chose a more elegant solution. It is quite possible that your Helper Object has been removed by
someone (user, module, whatever) and removing the Helper Object in that case can lead to a
crash.You can create an invisible tag sitting on the helper object. This tag should check if _your tag_
still exists, and if it does not, it can remove the object. (Choose to do this in a Message() calle since
scene modifications in TagData::Execute() or similar methods is not recommended by MAXON).Thanks Niklas! Yes, this is an elegant solution. In my case, however, the helper object is totally invisible. It does not appear in the work space, it is also hidden in the object browser. The user has no knowledge about its existence. So I can use the more simpler method in this case.
-
On 08/08/2013 at 05:56, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Thanks Niklas! Yes, this is an elegant solution. In my case, however, the helper object is totally invisible. It does not appear in the work space, it is also hidden in the object browser. The user has no knowledge about its existence. So I can use the more simpler method in this case.
May I ask you why you even need this helper object then?
-
On 08/08/2013 at 06:45, xxxxxxxx wrote:
Originally posted by xxxxxxxx
May I ask you why you even need this helper object then?
The only solution I found so far, here is the problem:
https://developers.maxon.net/forum/topic/7246/8326_constrain-rotation-to-object-with-skewed-axis&KW= -
On 08/08/2013 at 07:14, xxxxxxxx wrote:
My suggestion is the best response. If the helper object is not in the document, you need to invoke more in-depth methods (like CopyTo()) to ensure that the class membership is retained upon an undo. That is, the object must be literally recognized during the free process and then reinstated during the undo process. CopyTo() is there to transport non-C4D relevant data/memory/information between various processes such as copies for undo or render and such. Think of it as memory you have allocated for the tag that must be reallocated when it is restored because it is not handled directly by C4D. Some of the information must be retained in the BaseContainer/Description of the tag so that the helper object can be 'reconstructed' on a user undo process.
Welcome to the wonderful world of the C4D SDK API.
-
On 08/08/2013 at 08:54, xxxxxxxx wrote:
Ok Robert,
but what is wrong with my approach, posted Today** at 1:28pm?
It works just fine! -
On 08/08/2013 at 09:12, xxxxxxxx wrote:
Times are displayed based on the timezone here.
I already told you: It might crash in various situations. Unless you do not own an object, you should not store a pointer to it and assume it is valid anytime. And in this case, when the object is inserted in the document, you are not the owner of the object.
-
On 08/08/2013 at 09:17, xxxxxxxx wrote:
The code has been modified in the mean time. I keep the BaseDocument, and search for the object to be removed, by the name. By doing this, I am not storing a pointer to it.
But I do store a pointer to the BaseDocument. -
On 08/08/2013 at 19:20, xxxxxxxx wrote:
Simply create a LINK description in your tag and set it to the helper object. If the object is deleted by the user, for instance, BaseLink knows about it.