Solved GetCache() bug

Hello PluginCafe 🙂

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

alt text


is it possible to bypass this behavior?


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:

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,

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

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