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

    Crash with GeListHead and TreeViewFunctions SetName()

    Cinema 4D SDK
    python r20 r21 r23
    2
    4
    705
    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.
    • M
      mp5gosu
      last edited by

      Hello,

      I noticed that when using a GeListHead for storing custom BaseList2D items leads to a crash when TreeViewFunctions' SetName is called.
      Is this a known bug/behavior?
      If not, what did I do wrong? 😉

      Here's a minimal example. Try to rename any ListItem with Double-Click -> Freeze.
      On R21 I did some more debugging and it turned out that obj in SetName() is of type long.

      import c4d
      from c4d import gui
      from c4d import plugins
      
      PLUGIN_ID = 1000001  # Test plugin id
      PLUGIN_ID_ND = 1000002  # Test plugin id
      
      
      class ListItem(plugins.NodeData):
          def Init(self, node):
              # do stuff here
              return True
      
      
      class Tvf(gui.TreeViewFunctions):
          def GetFirst(self, root, userdata):
              if not root:
                  return None
              return root.GetFirst()
      
      
          def GetNext(self, root, userdata, obj):
              return obj.GetNext()
      
      
          def GetName(self, root, userdata, obj):
              return obj.GetName()
      
      
          def SetName(self, root, userdata, obj, str):
              obj.SetName(str)
      
      
      class TestDialog(gui.GeDialog):
          def __init__(self):
              self.items = c4d.GeListHead()
              self.treegui = None
              self.tvf = Tvf()
      
      
          def add_item(self):
              item = c4d.BaseList2D(PLUGIN_ID_ND)
              item.SetName("ListItem")
              item.InsertUnder(self.items)
      
      
          def CreateLayout(self):
              settings = c4d.BaseContainer()
              settings.SetBool(c4d.TREEVIEW_HAS_HEADER, True)
      
              self.treegui = self.AddCustomGui(0, c4d.CUSTOMGUI_TREEVIEW, "",
                                               c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT,
                                               300,
                                               300,
                                               settings)
      
              return True
      
      
          def InitValues(self):
              for x in range(5):
                  self.add_item()
      
              layout_bc = c4d.BaseContainer()
              layout_bc.SetInt32(0, c4d.LV_TREE)
              self.treegui.SetLayout(1, layout_bc)
      
              self.treegui.SetHeaderText(0, "Name")
              self.treegui.Refresh()
      
              self.treegui.SetRoot(self.items, self.tvf, None)
              return True
      
      
      class TestCommand(plugins.CommandData):
          def __init__(self):
              self.dlg = None
      
      
          def Register(self):
              return plugins.RegisterCommandPlugin(PLUGIN_ID, "Test-Plugin", 0, None, None, self)
      
      
          def Execute(self, doc):
              if self.dlg is None:
                  self.dlg = TestDialog()
      
              return self.dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaulth=400, defaultw=400)
      
      
          def RestoreLayout(self, sec_ref):
              if self.dlg is None:
                  self.dlg = TestDialog()
      
              return self.dlg.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
      
      
      if __name__ == '__main__':
          TestCommand().Register()
          plugins.RegisterNodePlugin(PLUGIN_ID_ND, "ListItem", c4d.PLUGINFLAG_HIDE, ListItem, None)
      
      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @mp5gosu unfortunately this is a bug, I'm still digging it so thanks for the report 🙂

        I will take you informed if I found a workaround.
        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

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

          Hi sorry for the late reply, just in case I'm still on it...
          However, the issue seems to happen only if the root is a GeListNode, if you use a python list instead, then it's working nicely.

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

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

            Hi @mp5gosu , I will set the topic as closed.

            Note that the fix will not come in the next update but don't worry we have it logged and it's on our list of things to fix in the future.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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