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

    GeListNode from ShaderData::Read function does not have a document?

    Cinema 4D SDK
    c++
    2
    3
    510
    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.
    • E
      ECHekman
      last edited by ECHekman

      Im loading in c4d project and want to get the Document the GeListNode belongs to, but i am getting a nullptr back.
      Is it expected for certain ShaderDatas not to be associated with a document?

      Code looks something like this:

      Bool SomeShaderDataPlugin::Read(GeListNode* node, HyperFile* hf, Int32 level)
      {
      	const BaseDocument* bd = node->GetDocument(); //bd is nullptr sometimes for some ShaderDatas
      	return SUPER::Read(node, hf, level);
      }
      
      1 Reply Last reply Reply Quote 0
      • E
        ECHekman
        last edited by

        After some digging it seems only some ShaderDatas dont have their document set. Other do have it.
        However after the Read, c4d will set the document at some point, because in the ::Message() function GetDocument does return a basedocument.

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by ferdinand

          Hi,
          yes, this is expected, and documented in NodeData::Read() / NodeData::Write() Manual. With that's said Read/Write is supposed to serialize data of your object (most of the time member variable) to the c4d file (the HyperFile), so accessing the BaseDocument is a sign of a bad design.

          May I ask why do you really want to access the BaseDocument in the Read function?

          Cheers,
          Maxime

          edit (@ferdinand): Just to be clear here, as we briefly talked about this in our morning meeting, what the docs write there is in a certain sense legacy information. When a branch, e.g., the Xbase (shader) branch of a material is being deserialized, the to be deserialized node is inserted into the branch and with that will have access to a document.

          But what @m_adam wrote is of course true, the document in this context is the fruit from the forbidden tree, as the node is not yet fully deserialized and certain parts of the GeListHead::Read, GeListNode::Read, BaseList2D::Read, ..., YourPluginLayer::Read deserialization chain might pull all sorts of tricks to carry out the deserialization, including temporarily removing the node from the scene graph.

          The documentation is therefore effectively still correct, as deserializing a node should never rely on the document context and accessing the document is forbidden in that context.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

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