tree images: SegFault...

Ok, i've developed a php parser to know classes, methods and properties on a textSTC.
Here is my pb, please don't speack about optimisation, i will work on tomorow.
My pb is to add image on item. I followed demo but it only use some wx.ART images. I need to use my own images.

I create a imagelist that i add on my tree, (i know, it can be done only once, but now i just test) and i set items representing "class" an image.
When i detect a class, and using image, a segfault appears. I know (by tracing the code) that the segfault appears on SetItemImage method.
So, maybe i'm wrong on how to set imagelist, or image... Please, can you help me ?

def onReDrawTree(self,event):
         event.Skip()
         e = self.current #get current STC editor
         p = phpParser() # my parser
         p.SetText(e.GetText())
         p.Parse()

         isz = (16,16)
         il = wx.ImageList(isz[0], isz[1])
         clidx = il.Add(wx.Bitmap('./icons/cl.png',wx.BITMAP_TYPE_PNG))

         tree = self.mainFrame.infoNoteBook.infoTree
         tree.SetImageList(il)
         tree.DeleteAllItems()

         classes = p.GetClasses()
         root = tree.AddRoot(_("Classes"))
         for cl in classes:
             #here is ok, print after this line works
             item = tree.AppendItem(root,cl._name)
             #print "class added"

             #here, segfault:
             tree.SetItemImage(item,clidx,wx.TreeItemIcon_Normal)
             tree.SetItemImage(item,clidx,wx.TreeItemIcon_Selected)
             for m in cl._methods:
                 mcl = tree.AppendItem(item,m._name)

         tree.Expand(root)

Robin Dunn wrote:

Metal3d wrote:

Ok, i've developed a php parser to know classes, methods and properties on a textSTC.
Here is my pb, please don't speack about optimisation, i will work on tomorow.
My pb is to add image on item. I followed demo but it only use some wx.ART images. I need to use my own images.

I create a imagelist that i add on my tree, (i know, it can be done only once, but now i just test) and i set items representing "class" an image.
When i detect a class, and using image, a segfault appears. I know (by tracing the code) that the segfault appears on SetItemImage method.
So, maybe i'm wrong on how to set imagelist, or image... Please, can you help me ?

def onReDrawTree(self,event):
        event.Skip()
        e = self.current #get current STC editor
        p = phpParser() # my parser
        p.SetText(e.GetText())
        p.Parse()

        isz = (16,16)
        il = wx.ImageList(isz[0], isz[1])
        clidx = il.Add(wx.Bitmap('./icons/cl.png',wx.BITMAP_TYPE_PNG))

        tree = self.mainFrame.infoNoteBook.infoTree

        tree.SetImageList(il)
        tree.DeleteAllItems()

You might try reversing these two lines, just in case the delete does something with the tree's image list. Also, you probably want to use AssignImageList instead of SetImageList as it appears that you want the tree to live longer than il does. Using Assign will give the tree ownership of the image list.

Ok, the error has desapeared while using Assignement and not Set. But in spite of your explanations i don't understand why there's 2 methods and them differences...
Thanks