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

    Setting up global plugin structs

    Cinema 4D SDK
    2
    3
    423
    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.
    • WickedPW
      WickedP
      last edited by

      Hi folks,

      I've had a persistent issue with setting up some plugins with global structs. I'm sure I've read about this previously, maybe something to do with symbols not being loaded before PluginStart() is called? I forget the details...

      Anyhow, is there a 'correct' way to setup a global struct for my plugin, that has BaseContainers, Strings etc in it? Take this for example, if I do this:

      // global struct
      struct MyStruct
      {
          BaseContainer bc;
      }mystruct;
      

      the plugin fails to start and I get a crash file with nothing in it. If I do this:

      // global struct
      struct MyStruct
      {
          std::vector< BaseContainer > bc;
      }mystruct;
      

      then the plugin loads. Obviously I have to take care of the array, but that aside. Is there a way of having a global struct load with Cinema objects, without cheating it like this? Or - is there a better cheat...

      WP.

      wickedp.com

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        after you struct declaration, you are adding mystruct witch will create a variable of the type of your structure.
        It try to allocate a BaseContainer that is unknown.

        If you add that to a Vector, as the vector is empty, it doesn't try to allocate a BaseContainer.

        I'm not sure why you need a global structure, but I would create a pointer and in pluginstart and pluginend take care of assign memory and free it.

        // global struct
        struct MyStruct
        {
            BaseContainer bc;
        }
        MyStruct *g_mystruct = nullptr;
        

        You can have a look at Entity Creation in our documentation.

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        WickedPW 1 Reply Last reply Reply Quote 0
        • WickedPW
          WickedP @Manuel
          last edited by

          Hi Manuel,

          what you say rings a bell. I was sure it was because the vector hadn't allocated anything yet.

          Global possibly wasn't the best way admittedly, it just started like that for convenience. But it ended up being a bit complex, there's a lot of things accessing it, so I didn't want to change it (for now).

          @m_magalhaes said in Setting up global plugin structs:

          create a pointer and in pluginstart and pluginend take care of assign memory and free it

          hadn't thought of that. Seems to work - I'll go with that! Thanks 👍

          WP.

          wickedp.com

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