SegFault clear-ing boxsizer

Hi Alls,

I have a segmentation fault trying to clear one BoxSizer. Probably this
is due to my errors, but i can't see them, so I decided to write.

I have an application with two areas: left and right. The left area
contains a TreeCtrl. The goal is: when a selection happens on the Tree,
rebuild it.

Application runs, but after an unpredictable number of selections, I
have a segmentation fault.

These are my sw versions:

  - python version -> 2.4
  - wxpython -> 2.6.4.0

Code follows: where is my error?

thanks in advance for your attention

best regards

···

############
### Code ###
############

class WApp(wx.Frame):

  def __init__(self):
    wx.Frame.__init__(self, ...)
    self.build_areas()

  def build_areas(self):

    # this boxes the left and right areas
    hsizer= wx.BoxSizer(wx.HORIZONTAL)

    # left panel
    self.larea= larea= wx.Panel(self, -1)
    # right panel
    self.rarea= rarea= wx.Panel(self, -1)

    hsizer.Add(larea, 1, wx.EXPAND | wx.ALL, 5)
    hsizer.Add(rarea, 4, wx.EXPAND | wx.ALL, 5)

    # i'll use these sizer to populate the areas
    self.lsizer= lsizer= wx.BoxSizer(wx.VERTICAL)
    self.rsizer= rsizer= wx.BoxSizer(wx.VERTICAL)

    self.SetSizer(hsizer)
    larea.SetSizer(lsizer)
    rarea.SetSizer(rsizer)

    self.build_browser()

  def _build_tree(self, parent):
    tid= wx.NewId()
    self.tree= tree= wx.TreeCtrl(parent, ...)
    root= tree.AddRoot('Root')
    tree.AppendItem(root, 'foo')
    tree.AppendItem(root, 'bar')

    tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.browser_selection, id= tid)
    return tree

  def build_browser(self):
    sizer= self.lsizer
    sizer.Clear(True)

    panel= wx.Panel(None, -1)
    tree= self._build_tree_portals(panel)
    sizer.Add(tree, 1, wx.EXPAND | wx.ALL, 2)

  def browser_selection(self, event):
    self.build_browser()

--
efphe
Today is Sweetmorn, the 9th day of The Aftermath in the YOLD 3174

Federico Tomassini wrote:

I have a segmentation fault trying to clear one BoxSizer. Probably this
is due to my errors, but i can't see them, so I decided to write.

I have an application with two areas: left and right. The left area
contains a TreeCtrl. The goal is: when a selection happens on the Tree,
rebuild it.

Application runs, but after an unpredictable number of selections, I
have a segmentation fault.
  
You create left and right panels, and sizers to control them. But, in
build_browser, you create a NEW panel (owned by no one), add your new
tree to that, then add the tree to the sizer that is still controlling
the left panel. You have ownership confusion.

Instead of creating a new panel in build_browser, I'm pretty sure you
just want to use self.larea.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.