Segmentation faults with wx.Notebook remove/delete page

Hi,

When I load my custom program file into the application, it first removes all pages from the notebook.
The first time I load in the file, everything's okay. If I have 54 tabs open, it'll close them all, and start the tab count from 0 again

If I already have a file of my own loaded, it will seg fault

        temp = {}
        f = open(self.filename, 'r')
        try:
            temp = cPickle.load(f)
        except (cPickle.UnpicklingError, ValueError, ImportError):
            wx.MessageBox("%s has corrupt Whyteboard data. No action taken."
                        % self.filename)
            return
        finally:
            f.close()

        self.gui.dialog = ProgressDialog(self.gui, "Loading...", 30)
        self.gui.dialog.Show()

        # Remove all tabs, thumbnails and tree note items
        self.gui.board = None
        self.gui.tabs.DeleteAllPages()
        self.gui.thumbs.remove_all()
        self.gui.notes.remove_all()
        self.gui.tab_count = 0

I narrowed it down by using print statements to the deleteallpages statement (printing after that wouldn't show up after the seg fault)

I tried using:

        for x in range(0, self.gui.tab_count):
            self.gui.tabs.DeletePage(x)

This causes seg faults too
I tried using and

        for x in range(0, self.gui.tab_count):
            self.gui.tabs.RemovePage(x)

But this behaves in the STRANGEST way. It doesn't actually remove -every- page, it will skip every other page. The reason for this is beyond me, I can't figure it out.

I'm using 2.8.9.2, Ubuntu 8.10, Python 2.5.2 (can't find an update for python 2.5.4 for ubuntu 8.10 anywhere)
Any ideas? :s

Hi Steven,

···

On Wed, Mar 18, 2009 at 7:09 AM, Steven Sproat wrote:

I tried using:

  for x in range\(0, self\.gui\.tab\_count\):
      self\.gui\.tabs\.DeletePage\(x\)

Try this:

         for x in range(self.gui.tab_count-1, -1, -1):
             self.gui.tabs.DeletePage(x)

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Andrea Gavana wrote:

Hi Steven,

I tried using:

      for x in range(0, self.gui.tab_count):
          self.gui.tabs.DeletePage(x)
    
Try this:

         for x in range(self.gui.tab_count-1, -1, -1):
             self.gui.tabs.DeletePage(x)

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Andrea,
I'm still getting seg faults while using that code. I changed the method call from deletepage to removepage, and that seems to have worked fine, I can now open one file, open another and the new one will remove all open tabs before loading itself. I can't figure out why I need to reverse iterate over my tabs though

Strangely, I noticed when I close my application with a savefile open, it'll show a seg fault in the console upon exiting. I dunnoo what that's related to, and seems ..recent. I'm definitely closing the file handles to any files I open

thanks,
Steve

···

On Wed, Mar 18, 2009 at 7:09 AM, Steven Sproat wrote:

Hello, sorry for the double reply, but I think I've narrowed the causes of the seg. faults down to my drawing window class recently adding in drag/drop support. (each tab in my notebook is an instance of that class)

class Whyteboard(wx.ScrolledWindow):
    """
    The drawing frame of the application.
    """

    def __init__(self, tab):
        """
        Initalise the window, class variables and bind mouse/paint events
        """
        wx.ScrolledWindow.__init__(self, tab, style=wx.CLIP_CHILDREN)
        self.virtual_size = (1000, 1000)
        self.SetVirtualSize(self.virtual_size)
        self.SetScrollRate(20, 20)
        self.SetBackgroundColour("White")
        self.SetDropTarget(tab.GetParent().file_drop)

class GUI(wx.Frame):
    """
    Combines all GUI elements to create the overall application
    """
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, title="Untitled - " + self.title)
        self.file_drop = FileDropTarget(self)

Commenting out the SetDropTarget line in Whyteboard removes the error.

I *think* I've managed to fix it now by removing the Whyteboard as the data source, and setting it as the GUI instead (it still loads a dragged image onto the correct tab)

I'm just a bit cautious about releasing this version now in case some errors are still there

Steven Sproat wrote:

Hello, sorry for the double reply, but I think I've narrowed the causes of the seg. faults down to my drawing window class recently adding in drag/drop support. (each tab in my notebook is an instance of that class)

class Whyteboard(wx.ScrolledWindow):
   """
   The drawing frame of the application.
   """

   def __init__(self, tab):
       """
       Initalise the window, class variables and bind mouse/paint events
       """
       wx.ScrolledWindow.__init__(self, tab, style=wx.CLIP_CHILDREN)
       self.virtual_size = (1000, 1000)
       self.SetVirtualSize(self.virtual_size)
       self.SetScrollRate(20, 20)
       self.SetBackgroundColour("White")
       self.SetDropTarget(tab.GetParent().file_drop)

class GUI(wx.Frame):
   """
   Combines all GUI elements to create the overall application
   """
   def __init__(self, parent):
       wx.Frame.__init__(self, parent, title="Untitled - " + self.title)
       self.file_drop = FileDropTarget(self)

Commenting out the SetDropTarget line in Whyteboard removes the error.

I *think* I've managed to fix it now by removing the Whyteboard as the data source, and setting it as the GUI instead (it still loads a dragged image onto the correct tab)

I'm just a bit cautious about releasing this version now in case some errors are still there
____________

Stupid question, but why are you misspelling "whiteboard"?

Mike

Mike Driscoll wrote:

Stupid question, but why are you misspelling "whiteboard"?

Mike
_______________________________________________

I didn't want to call my application Whiteboard, as it's too general so I was trying to give it some uniqueness (pun on white/byte, perhaps). I was thinking of some py*- related name, but decided that's "cheesy" in most cases :slight_smile:

Steve

Steven Sproat wrote:

Andrea Gavana wrote:

Hi Steven,

I tried using:

      for x in range(0, self.gui.tab_count):
          self.gui.tabs.DeletePage(x)
    
Try this:

         for x in range(self.gui.tab_count-1, -1, -1):
             self.gui.tabs.DeletePage(x)

Hi Andrea,
I'm still getting seg faults while using that code. I changed the method call from deletepage to removepage, and that seems to have worked fine,

Because RemovePage does not actually delete the page windows, so you are
just hiding the problem. (See next message.)

I can now open one file, open another and the new one will remove all open tabs before loading itself. I can't figure out why I need to reverse iterate over my tabs though

Because when you delete/remove page zero then page one moves to the zero
position. Then when your loop iterates and you delete page 1 (which
used to be 2) then page 2 (which used to be 3) moves up a slot to 1 and your iteration moves to position 2, leaving the new zero and one there.
This is a better way if you want to do them in order:

  while nb.GetPageCount():
    nb.DeletePage(0);

Strangely, I noticed when I close my application with a savefile open, it'll show a seg fault in the console upon exiting. I dunnoo what that's related to, and seems ..recent. I'm definitely closing the file handles to any files I open

It's just the windows that you never deleted (or destroyed) finally
being destroyed and it is running into the same bug again.

···

On Wed, Mar 18, 2009 at 7:09 AM, Steven Sproat wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Steven Sproat wrote:

Hello, sorry for the double reply, but I think I've narrowed the causes of the seg. faults down to my drawing window class recently adding in drag/drop support. (each tab in my notebook is an instance of that class)

       self.SetDropTarget(tab.GetParent().file_drop)

You can not share drop targets. Each window will think that it owns it
exclusively and when the window is destroyed it will also destroy the
drop target, so when the second one destroys it then it has already been
done and you crash. In C++ this is known as one of the zillion ways
that you can shoot yourself in the foot. :wink: So give each page window
it's own drop target instance.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Steven Sproat wrote:

Hello, sorry for the double reply, but I think I've narrowed the causes of the seg. faults down to my drawing window class recently adding in drag/drop support. (each tab in my notebook is an instance of that class)

       self.SetDropTarget(tab.GetParent().file_drop)

You can not share drop targets. Each window will think that it owns it
exclusively and when the window is destroyed it will also destroy the
drop target, so when the second one destroys it then it has already been
done and you crash. In C++ this is known as one of the zillion ways
that you can shoot yourself in the foot. :wink: So give each page window
it's own drop target instance.

Thanks Robin for your replies, they always prove insightful.
cheers,
Steven