• Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login
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
  • Register
  • Login

Different behaviour with Resource File? R20/R21

Cinema 4D SDK
2
5
678
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.
  • L
    lasselauch
    last edited by Jan 23, 2020, 9:03 AM

    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:

    ./plugins/
       |-- myplugin/
            |-- myplugin.pyp
            |-- modules/
                 |-- maindialog.py
            |-- 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__
    

    maindialog.py:

    class OptionsDialog(c4d.gui.GeDialog):
        def CreateLayout(self):
            #Initialize Resource File from 'res' Folder.
            c4d.plugins.GeResource().Init(os.path.dirname(__file__))
            self.LoadDialogResource(ids.IDD_DIALOG)
    

    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..?

    Thanks,
    Lasse

    1 Reply Last reply Reply Quote 0
    • M
      m_adam
      last edited by Jan 23, 2020, 1:57 PM

      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 maindialog.py doesn't help then could you please share a minified version of your project?

      Cheers,
      Maxime

      MAXON SDK Specialist

      Development Blog, MAXON Registered Developer

      1 Reply Last reply Reply Quote 0
      • L
        lasselauch
        last edited by Jan 23, 2020, 2:48 PM

        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!

        Thanks,
        Lasse

        1 Reply Last reply Reply Quote 0
        • L
          lasselauch
          last edited by Jan 23, 2020, 4:13 PM

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

          https://developers.maxon.net/docs/py/2023_2/modules/c4d.gui/BaseCustomGui/BitmapButtonCustomGui/index.html?highlight=setimage#BitmapButtonCustomGui.SetImage

              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.

          1 Reply Last reply Reply Quote 1
          • M
            m_adam
            last edited by m_adam Jan 23, 2020, 4:37 PM Jan 23, 2020, 4:32 PM

            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.
            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            5 out of 5
            • First post
              Last post