Segmentation fault with two frames...

Hi!

I get a segmentation fault when closing a second frame. I trimmed a
lot my program, and have the same behaviour in the code I put at the
end of the mail.

To reproduce it go to File, New, and close the frame that get opened.

I'm using wxPython 2.5.3, on Ubuntu Linux, with Python 2.4.1a0. The
same behaviour is reproducible in a Fedora Core 4 and in Windows
(don't know right now wxPython and Python versions in those systems).

Here's the code. Please help, as I don't know how to debug this error, :frowning:

Thank you!!

···

-----------------------------------------------------------------------

import wx

class OtherFrame(wx.Frame):
    def __init__(self, parent):

        # initialize the frame
        wx.Frame.__init__(self, parent, wx.NewId(), "Title")

        panel1 = wx.Panel(self, wx.NewId())
        date1 = wx.StaticText(panel1, -1, "Date 1")
        box1 = wx.BoxSizer(wx.HORIZONTAL)
        box1.Add(date1, 0)
        panel1.SetSizer(box1)

        panel2 = wx.Panel(self, wx.NewId())
        date2 = wx.StaticText(panel2, -1, "Date 2")
        box2 = wx.BoxSizer(wx.HORIZONTAL)
        box2.Add(date2, 0)
        panel2.SetSizer(box2)

        # put everything in a box
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(box1, 0, wx.EXPAND | wx.ALL, border=0)
        box.Add(box2, 0, wx.EXPAND | wx.ALL, border=0)
        box.Fit(self)
        self.SetSizer(box)
        self.SetAutoLayout(True)

        self.Show(True)
        return

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title, pos=(-1,-1),
size=wx.Size(200, 200))

        menuBar = wx.MenuBar()
        menu = wx.Menu()
        menu.Append(1, "&New", "Test")
        menuBar.Append(menu, "&File")
        wx.EVT_MENU(self, 1, self.onTest)
        self.SetMenuBar(menuBar)

        self.Show(True)
        return

    def onTest(self, event):
        OtherFrame(self)
        return

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "Test")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

-----------------------------------------------------------------------

. Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/

As confirmation, the crash also occurs on RH FC2 with Python 2.4 and
wxPython 2.4.2.4. The partial traceback after the segmentation
fault is below.

/Jean Brouwers

#0 0x00fb030b in wxSizerItem::~wxSizerItem () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#1 0x00f8c90d in wxObjectListNode::DeleteData () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#2 0x00f8c5c5 in wxListBase::DoDeleteNode () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#3 0x00f8c745 in wxListBase::Clear () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#4 0x00fb128a in wxSizer::Clear () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#5 0x00fb0a4b in wxSizer::~wxSizer () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#6 0x00fb40d0 in wxBoxSizer::~wxBoxSizer () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#7 0x00fe8bb3 in wxWindowBase::~wxWindowBase () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#8 0x00eedd43 in wxWindow::~wxWindow () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#9 0x00fcd4e5 in wxTopLevelWindowBase::~wxTopLevelWindowBase () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#10 0x00ee5fd6 in wxTopLevelWindowGTK::~wxTopLevelWindowGTK () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#11 0x00f56e37 in wxFrameBase::~wxFrameBase () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#12 0x00ebd2a4 in wxFrame::~wxFrame () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#13 0x00e98dc8 in wxApp::DeletePendingObjects () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#14 0x00e98b5f in wxApp::OnIdle () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#15 0x00f317d5 in wxEvtHandler::SearchEventTable () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#16 0x00f3158b in wxEvtHandler::ProcessEvent () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#17 0x00e98ad7 in wxApp::ProcessIdle () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#18 0x00e9838b in wxapp_idle_callback () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#19 0x00915683 in g_child_watch_add () from /usr/lib/libglib-2.0.so.0
#20 0x00912252 in g_main_depth () from /usr/lib/libglib-2.0.so.0
#21 0x00913348 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#22 0x00913680 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#23 0x00913cc3 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#24 0x060f2923 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#25 0x00e98d16 in wxApp::MainLoop () from …/wxpython2.4.2.4/lib/libwx_gtk2d-2.4.so
#26 0x0016252b in wxPyApp::MainLoop (this=0x0) at src/helpers.cpp:131
#27 0x0016baea in _wrap_wxPyApp_MainLoop (self=0x0, args=0xb7a8a10c, kwargs=0xb7a9a3e4) at src/gtk/wx.cpp:1383

···

On 8/23/05, Facundo Batista facundobatista@gmail.com wrote:

Hi!

I get a segmentation fault when closing a second frame. I trimmed a
lot my program, and have the same behaviour in the code I put at the
end of the mail.

To reproduce it go to File, New, and close the frame that get opened.

I’m using wxPython 2.5.3, on Ubuntu Linux, with Python 2.4.1a0. The
same behaviour is reproducible in a Fedora Core 4 and in Windows
(don’t know right now wxPython and Python versions in those systems).

Here’s the code. Please help, as I don’t know how to debug this error, :frowning:

Thank you!!


import wx

class OtherFrame(wx.Frame
):
def init(self, parent):

    # initialize the frame
    wx.Frame.__init__(self, parent, wx.NewId(), "Title")

    panel1 = wx.Panel(self, wx.NewId())
    date1 = wx.StaticText

(panel1, -1, “Date 1”)
box1 = wx.BoxSizer(wx.HORIZONTAL)
box1.Add(date1, 0)
panel1.SetSizer(box1)

    panel2 = wx.Panel(self, wx.NewId())
    date2 = wx.StaticText

(panel2, -1, “Date 2”)
box2 = wx.BoxSizer(wx.HORIZONTAL)
box2.Add(date2, 0)
panel2.SetSizer(box2)

    # put everything in a box
    box = wx.BoxSizer(wx.VERTICAL

)
box.Add(box1, 0, wx.EXPAND | wx.ALL, border=0)
box.Add(box2, 0, wx.EXPAND | wx.ALL, border=0)
box.Fit(self)
self.SetSizer(box)
self.SetAutoLayout(True)

self.Show(True)
return

class MyFrame(wx.Frame):
def init(self, parent, ID, title):
wx.Frame.init(self, parent, ID, title, pos=(-1,-1),
size=wx.Size(200, 200))

    menuBar = wx.MenuBar()
    menu = wx.Menu()
    menu.Append(1, "&New", "Test")
    menuBar.Append(menu, "&File")
    wx.EVT_MENU(self, 1, self.onTest)
    self.SetMenuBar

(menuBar)

    self.Show(True)
    return

def onTest(self, event):
    OtherFrame(self)
    return

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, “Test”)

    frame.Show(True)
    self.SetTopWindow(frame)
    return True

if name == “main”:
app = MyApp(0)
app.MainLoop()


. Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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

Hi,

The offending lines are:

        box.Add(box1, 0, flag = wx.EXPAND | wx.ALL, border=0)
        box.Add(box2, 0, flag = wx.EXPAND | wx.ALL, border=0)

they should be:

        box.Add(panel1, 0, flag = wx.EXPAND | wx.ALL, border=0)
        box.Add(panel2, 0, flag = wx.EXPAND | wx.ALL, border=0)

I also commented out some lines, which might have had to do with it but I really think it is these two lines.

The complete file is attached.

Don't ask me why it crashes the way it does. I found in the past that if you do things which are not really allowed with sizers its gets really touchy.

The way I went about debugging this was just commenting just about everything out, then it did not crash anymore, so I started adding things back in until it crashed and then it took a moment to look at that section of code to see what might cause the problem.

See you
Werner

Facundo Batista wrote:

crashmod.py (1.65 KB)

···

Hi!

I get a segmentation fault when closing a second frame. I trimmed a
lot my program, and have the same behaviour in the code I put at the
end of the mail.

To reproduce it go to File, New, and close the frame that get opened.

I'm using wxPython 2.5.3, on Ubuntu Linux, with Python 2.4.1a0. The
same behaviour is reproducible in a Fedora Core 4 and in Windows
(don't know right now wxPython and Python versions in those systems).

Here's the code. Please help, as I don't know how to debug this error, :frowning:

Thank you!!

-----------------------------------------------------------------------

import wx

class OtherFrame(wx.Frame):
   def __init__(self, parent):

       # initialize the frame
       wx.Frame.__init__(self, parent, wx.NewId(), "Title")

       panel1 = wx.Panel(self, wx.NewId())
       date1 = wx.StaticText(panel1, -1, "Date 1")
       box1 = wx.BoxSizer(wx.HORIZONTAL)
       box1.Add(date1, 0)
       panel1.SetSizer(box1)

       panel2 = wx.Panel(self, wx.NewId())
       date2 = wx.StaticText(panel2, -1, "Date 2")
       box2 = wx.BoxSizer(wx.HORIZONTAL)
       box2.Add(date2, 0)
       panel2.SetSizer(box2)

       # put everything in a box
       box = wx.BoxSizer(wx.VERTICAL)
       box.Add(box1, 0, wx.EXPAND | wx.ALL, border=0)
       box.Add(box2, 0, wx.EXPAND | wx.ALL, border=0)
       box.Fit(self)
       self.SetSizer(box)
       self.SetAutoLayout(True)

       self.Show(True)
       return

class MyFrame(wx.Frame):
   def __init__(self, parent, ID, title):
       wx.Frame.__init__(self, parent, ID, title, pos=(-1,-1),
size=wx.Size(200, 200))

       menuBar = wx.MenuBar()
       menu = wx.Menu()
       menu.Append(1, "&New", "Test")
       menuBar.Append(menu, "&File")
       wx.EVT_MENU(self, 1, self.onTest)
       self.SetMenuBar(menuBar)

       self.Show(True)
       return

   def onTest(self, event):
       OtherFrame(self)
       return

class MyApp(wx.App):
   def OnInit(self):
       frame = MyFrame(None, -1, "Test")
       frame.Show(True)
       self.SetTopWindow(frame)
       return True

if __name__ == "__main__":
   app = MyApp(0)
   app.MainLoop()

-----------------------------------------------------------------------

. Facundo

Blog: Bitácora de Vuelo
PyAr: http://www.python.org/ar/

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

Works! Works! Thank you very much.

Looking at it, it's clear that I put it wrong.

Do you know if there's a "concept" tutorial where it explains
something like the following?:

  - You should only put panels in a sizer
  - the widgets must have, as parent, a panel and not a sizer
  - the sizer must be related to the panel with a SetSizer
  - etc....

I found that, with all that I read, I'm always confused with this
structure... :frowning:

Thank you!

. Facundo

Blog: Bitácora de Vuelo
PyAr: http://www.python.org/ar/

···

2005/8/23, Werner F. Bruhin <werner.bruhin@free.fr>:

Hi,

The offending lines are: