Solved Different behaviour with Resource File? R20/R21

Hi there,

I'm experiencing some difficulties in R21 with __res__ and my maindialog.

This is my folder structure and what I currently have implemented:

   |-- myplugin/
        |-- myplugin.pyp
        |-- modules/
        |-- res/
             |-- usual suspects here

myplugin.pyp (I'm using the localimport from Niklas Rosenstein):

# localimport-v1.7.3-blob-mcw99
with localimport('.') as _importer:
    from modules import maindialog
    from modules.maindialog import OptionsDialog
    maindialog.__res__ = __res__

class OptionsDialog(c4d.gui.GeDialog):
    def CreateLayout(self):
        #Initialize Resource File from 'res' Folder.

While this is working in all versions from R17-R20, I'm experiencing instant crashes and freezes in R21. Any ideas how I can fix this or how I can optimize my code..?


Hi @lasselauch could you try to define the resource more globally by defining the __res__ module.
For more information see a similar topic Issue with registering a ToolData.

If defining a __res__ variable in your doesn't help then could you please share a minified version of your project?


Hi Maxime,

thanks for taking a look! I've already tried to define it globally and it had the same effect. I'll try to share a minified version as soon as possible!


Wow, after some investigating I noticed that apperently BitmapButtonCustomGui.SetImage changed in R21.

    def fillResetButtons(self, buttonid):
        button = self.FindCustomGui(buttonid, c4d.CUSTOMGUI_BITMAPBUTTON)
        icon = c4d.bitmaps.InitResourceBitmap(c4d.RESOURCEIMAGE_CLEARSELECTION)
        button.SetImage(icon, copybmp=True)

I just had to set the copybmp to True which was False and seemed to worked fine in all other versions.

BitmapButtonCustomGui.SetImage was just extended in R21 to support c4d.IconData as well, but the behavior didn't changed.

I guess the issue is more related to R21 What is News - Fixes

  • Fixed a memory leak in bitmaps.InitResourceBitmap().

So basically previously c4d.bitmaps.InitResourceBitmap produced a memory leak where the allocated BaseBitmap was never released, so that's why previously without copying it, it was working.
But you should pass True to copyBmp to copy the BaseBitmap now since the BaseBitmap will be released at the destruction of icon variable by the Python Garbage Collection, but if you don't copy it, the BitmapButtonCustomGui will still use the previous BaseBitmap pointer, which will produce a crash since it will be dead.

Glad you found the issue.