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

    Event on tag removed or C4D closed?

    SDK Help
    0
    12
    917
    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
      Helper
      last edited by

      On 19/06/2013 at 01:46, xxxxxxxx wrote:

      Please see NodeData::Free() in the SDK. Your tag, being a TagData, inherits NodeData, so when the tag is deleted Free() is called. Since it passes a GeListNode you can use this to delete the null object. That's what Free() is for, as the SDK says, to de-allocate stuff you've allocated.

      This will also be called when the scene is closed (so it will be called when Cinema is closed, too). One caveat - if the user *moves* your tag to another object, I don't think Free is called. In fact I don't know what the sequence of events is then.

      Steve

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

        On 19/06/2013 at 02:02, xxxxxxxx wrote:

        Hi and thanks to both of you! This cleared up a lot of things.

        Originally posted by xxxxxxxx

        1. I hope you are creating the helper object from a method called from the main thread, not from any other like Execute().

        The Null is created when the user pushes a button. And then sits on the remote object.
        If I remove my tag as it is now, the Null remains there. But I want to remove it, which is easy, I just look for it by iterating the remote object's hierarchy. 
        The Null is not kept anywhere at all in the tag. The owner, though, as a linked object.

        Originally posted by xxxxxxxx

        What to do when the project closes?  Why should there be something left to be done?
        What to do when C4D closes?  Same question.

        This is a good answer 🙂

        Originally posted by xxxxxxxx

        Please see NodeData::Free() in the SDK.

        Bingo!! That's what I am after. I will look into that!
        And the advice to print the messages is a very good one.

        What I still am a little unsure about is how to manage the life cycle of custom classes I design (not C4D objects). These are classes I very often use, I  store them in BaseArrays*, they hold several values, are placeholders. I have looked at code others have written and I don't see much of freeing up stuff. I am used to (from Delphi's Pascal) to have try..catch..finally blocks, and free up everything as soon as it is used.

        I use several kinds of object, some are stored in the BaseContainer, some are just a public property of my tag, and before I publish my tag I must ensure that all this is proper and that I have no memory leaks. Right now my focus is on making things work.

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

          On 19/06/2013 at 02:41, xxxxxxxx wrote:

          Here is an update,  NodeData::Free() is called when the tag is removed, yes. Good. But it is also called when the project is closed. Now, doing my "cleanup" when the projects closes, seems to have no negative effect. But I currently see  no way to differ between the project being closed on on side, and just the tag being removed, on the other side. NodeData::Free() is called regardless.

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

            On 19/06/2013 at 03:01, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            What to do if the user removes the tag? I'm not sure if there is a message sent when the tag is
            removed. Just print every call to Message() and see if there is. Otherwise, you're left to leave the
            Null-Object in the scene and the user must remove it him/herself.

            Have you checked the docs, or as I quoted above, checked the messages you recieve? Just as there
            is a MSG_MENUPREPARE message sent when an object is inserted into a document, there might be
            a message sent when the object is removed from the document.

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

              On 19/06/2013 at 03:03, xxxxxxxx wrote:

              The only message I saw when I removed the tag, was MSG_DESCRIPTION_POSTSETPARAMETER
              But this message also occurs a lot of times, without the tag being removed.

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

                On 19/06/2013 at 04:28, xxxxxxxx wrote:

                Originally posted by xxxxxxxx

                Here is an update, <span style=": rgb248, 248, 252;"> NodeData::Free() is called when the tag is removed, yes. Good. But it is also called when the project is closed. Now, doing my "cleanup" when the projects closes, seems to have no negative effect. But I currently see  no way to differ between the project being closed on on side, and just the tag being removed, on the other side. </span><span style=": rgb248, 248, 252;">NodeData::Free() is called regardless.</span>

                Why does it matter? In both cases you want to free up memory that's been allocated. Or am I missing something?

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

                  On 19/06/2013 at 04:58, xxxxxxxx wrote:

                  You are correct Steve, I was thinking about removing the aforementioned Null object. Of course is this Free() very important for any resource allocated inside the plugin.

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

                    On 19/06/2013 at 05:03, xxxxxxxx wrote:

                    there is the msg_documentinfo message which allows you to react to various document related 
                    events (loading, merging, saving and so on, some of the events are separated into a message 
                    before the event and a message after the event). you can also just listen for the core message 
                    evmsg_change and then compare the currently active document with a reference to the last
                    known document (that has been the official maxon advice on the topic).

                    as steve already pointed out you should treat freeing a node always like your document is about 
                    to be closed (at least I do understand it that way). There is also PluginMessage() in c4d_plugin 
                    which allows you to react to c4ds startup and closing process.

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

                      On 19/06/2013 at 05:33, xxxxxxxx wrote:

                      Great littledevil, very important information.
                      _
                      _
                      > that has been the official maxon advice on the topic
                      I see this sometimes, referring to Maxon, and wonder if it is  in the SDK, or if it stems from direct conversation with Maxon.

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

                        On 19/06/2013 at 06:12, xxxxxxxx wrote:

                        Originally posted by xxxxxxxx

                        Great littledevil, very important information.
                        _
                        _
                        > that has been the official maxon advice on the topic
                        I see this sometimes, referring to Maxon, and wonder if it is  in the SDK, or if it stems from direct conversation with Maxon.

                        it is here in one of the threads, i am not sure anymore if i did ask the question myself, or if i 
                        read the answer in another thread. i just know that the topic about reacting to document 
                        events does come up regularly and matthias bober (one of the maxon devs) said that listening 
                        to evmsg_change would be the common way to do that.

                        i have no idea what about the document messages is wrong, i just suspect this was a general
                        answer, including plugins which do not have access to nodedata messages, but only to core
                        messages, but that is only my interpretation.

                        happy rendering,
                        ferdinand

                        ps: ah found it:

                        https://developers.maxon.net/forum/topic/6232/6581_notification-on-change-of-active-document&KW=document+save

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