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

    GetCache() bug

    Cinema 4D SDK
    python
    3
    4
    930
    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.
    • merkvilsonM
      merkvilson
      last edited by merkvilson

      Hello PluginCafe 🙂

      I tried to insert a cache of selected object into the doc via Console but I got this error/crash.

      alt text

      doc.InsertObject(op.GetCache())

      is it possible to bypass this behavior?

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        this is no bug of the Python API. The code is just unsafe.

        A given BaseObject (generator) owns the content of its cache. This cache may be a BaseObject (and subsequent child objects) or nothing - None.

        So if you operate with a cache you should always check if that cache is actually set. GetCache() can always return None.

        cache = op.GetCache()
        if cache is None:
            return
        

        But the real problem is that the given BaseObject owns the content of the cache. In your code, you take the cache and inset it into the BaseDocument. Both the generator and theBaseObject now think they do have sole ownership of the cache content. This can't work and is a perfect recipe for any kind of undefined behaviour - including a crash.

        So you cannot insert the cache into the BaseDocument. You must create a copy of the cache (GetClone()) and insert that copy into the BaseDocument.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • merkvilsonM
          merkvilson
          last edited by

          Thanks, Sebastian for detailed explanation 🙂
          But this still can be considered as a bug since it CRASHES c4d instead of raising an error message.

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

            Hi @merkvilson, this feedback has been communicated to our development team.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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