Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    BaseContainer bc = NULL;

    Cinema 4D SDK
    c++ r20
    2
    3
    557
    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.
    • R
      rui_mac
      last edited by a_block

      Previously (pre R20) I certain occasions, I started my public BaseContainers as NULL's, inside my plugin class, because I needed to start with empty containers.
      So, later, only if the BaseContainer was not NULL (if I could initialize it inside one of the methods), I would perform operations on them.
      But now, I can't seem to be able to declare BaseContainers as NULLs (or nullptr).
      I know I could simply declare them and then only initialise them inside the Init method.
      But, how can I check if a BaseContainer is empty?

      1 Reply Last reply Reply Quote 0
      • a_blockA
        a_block
        last edited by

        Hi,

        actually I'm not aware of any change of the Cinema 4D R20 API, which forbids definition of a BaseContainer pointer and assigning nullptr to it.
        On the other hand the code you posted into the headline of this subject (I recommend to write code rather into the actual post, where can also use code tags), doesn't look like you are actually defining a pointer variable.

        BaseContainer bc = nullptr; // This line shouldn't compile
        

        To be honest I'm not sure why this would have compiled in the R19 or any previous SDK.
        It would rather need to look like so:

        BaseContainer *bc = nullptr;
        

        And maybe it's also not the safest approach at all, as it leads to unrecoverable errors (aka crashes) if you forget to implement the nullptr check somewhere. Instead you could unconditionally create the BaseContainer upon initialization and detect the validity of its content by writing a boolean value representing the state into the container itself. Just a suggestion.

        The BaseContainer API does not directly provide any means to detect if the container is empty. But you could for example use BrowseContainer to check, if there's content. See also the BaseContainer manual for a snippet on how to use it.

        And finally as you seem to be porting your code to R20 anyway, you may also want to take a look at the DataDictionaryInterface (and the DataDictionary manual). While not being a 1:1 replacement, it can be a way more powerful solution for most use-cases of a BaseContainer.

        Cheers,
        Andreas

        1 Reply Last reply Reply Quote 2
        • R
          rui_mac
          last edited by

          Thank you Andres.
          I'm going with the boolean variable to flag if a BaseContainer contains something or not.

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