Segmentation Fault on wx.Listbook::DeleteAllPages()

Hi everyone !!!

i'm running python-wxgtk2.6 (2.6.1.2ubuntu2) and always get a Segmentation Fault doing wx.Listbook::DeleteAllPages().

Even this small buggy app does!!! (running on python interpreter):

import wx
app = wx.App()
myListbook = wx.Listbook(None)
myListbook.DeleteAllPages()

Segmentation Fault

What happens ???

You can’t create a Listbook without giving it a parent. When I execute that code, it crashes before the DeleteAllPages() call. When you say that “even this small buggy app” crashes, it’s because the app neglects several things that it fails to DeleteAllPages().

Are you sure that you create Listbooks properly? You need to give the Listbook a parent, such as a wx.Dialog or a wx.Frame, before you can create the Listbook.

My guess is that you get the segmentation fault because you don’t create the Listbooks properly, then you try to operate on them.

···

On 8/13/06, Felix felixonta@teleline.es wrote:

Hi everyone !!!

i’m running python-wxgtk2.6 (2.6.1.2ubuntu2) and always get a Segmentation Fault doing wx.Listbook::DeleteAllPages().

Even this small buggy app does!!! (running on python interpreter):

import wx
app = wx.App()
myListbook = wx.Listbook(None)
myListbook.DeleteAllPages()
Segmentation Fault

What happens ???


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

You was right, i tried to simplify the problem but failed building the example.
Here you get a simple but more elaborated example of the problem.

import wx

app = wx.App()
myFrame = wx.Frame(None)

myListbook = wx.Listbook(myFrame)

myListbook.AddPage(wx.Panel(myListbook, -1), 'Page 1')
myListbook.AddPage(wx.Panel(myListbook, -1), 'Page 2')
myListbook.AddPage(wx.Panel(myListbook, -1), 'Page 3')

#If you comment this line, the application works !
#If not ---> Segmentation Fault. Why???
myListbook.DeleteAllPages()

app.SetTopWindow(myFrame)
myFrame.Show()
app.MainLoop()

···

On Sun, 13 Aug 2006 11:52:11 -0400 "Saketh Bhamidipati" <saketh.bhamidipati@gmail.com> wrote:

My guess is that you get the segmentation fault because you don't create the
Listbooks properly, then you try to operate on them.

Felix wrote:

···

On Sun, 13 Aug 2006 11:52:11 -0400 > "Saketh Bhamidipati" <saketh.bhamidipati@gmail.com> wrote:

My guess is that you get the segmentation fault because you don't create the
Listbooks properly, then you try to operate on them.

You was right, i tried to simplify the problem but failed building the example.
Here you get a simple but more elaborated example of the problem.

import wx

app = wx.App()
myFrame = wx.Frame(None)

myListbook = wx.Listbook(myFrame)

myListbook.AddPage(wx.Panel(myListbook, -1), 'Page 1')
myListbook.AddPage(wx.Panel(myListbook, -1), 'Page 2')
myListbook.AddPage(wx.Panel(myListbook, -1), 'Page 3')

#If you comment this line, the application works !
#If not ---> Segmentation Fault. Why???
myListbook.DeleteAllPages()

There is a bug that doesn't reset the current page index when the pages are deleted, so the next time it tries to access the current page from the empty array it crashes. It's already been fixed in 2.7, I'll see if it can be backported to 2.6.

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

It would be great. Thanks Robin.

But, if this is a bug, can you tell me the best way to populate and depopulate a Listbook programmaticaly??

···

On Mon, 14 Aug 2006 10:19:00 -0700 Robin Dunn <robin@alldunn.com> wrote:

There is a bug that doesn't reset the current page index when the pages
are deleted, so the next time it tries to access the current page from
the empty array it crashes. It's already been fixed in 2.7, I'll see if
it can be backported to 2.6.

Populating a list is simple enough - you did it in the example you gave.

Depopulating a list can be done in many ways. I don’t know if this is the best one, but it works:

while not myListbook.GetPageCount() == 0:
myListbook.RemovePage(myListbook.GetSelection
())

You could also use a for loop.

···

On 8/14/06, Felix felixonta@teleline.es wrote:

On Mon, 14 Aug 2006 10:19:00 -0700 > Robin Dunn robin@alldunn.com wrote:

There is a bug that doesn’t reset the current page index when the pages
are deleted, so the next time it tries to access the current page from

the empty array it crashes. It’s already been fixed in 2.7, I’ll see if
it can be backported to 2.6.

It would be great. Thanks Robin.

But, if this is a bug, can you tell me the best way to populate and depopulate a Listbook programmaticaly??


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Saketh Bhamidipati wrote:

Depopulating a list can be done in many ways. I don't know if this is the best one, but it works:

while not myListbook.GetPageCount() == 0:
    myListbook.RemovePage(myListbook.GetSelection ())

Or, for a slightly more concise version:

while myListbook.GetPageCount():
    myListbook.RemovePage(myListbook.GetSelection())

Tim

Felix wrote:

···

On Mon, 14 Aug 2006 10:19:00 -0700 > Robin Dunn <robin@alldunn.com> wrote:

There is a bug that doesn't reset the current page index when the pages are deleted, so the next time it tries to access the current page from the empty array it crashes. It's already been fixed in 2.7, I'll see if it can be backported to 2.6.

It would be great. Thanks Robin.

But, if this is a bug, can you tell me the best way to populate and depopulate a Listbook programmaticaly??

The problem happens when the first size event after DeleteAllPages has been called tries to access the array of pages with a bad index. So if after you delete all the pages if you add one, and be sure that it is the selected one, then it should be ok.

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