Ticket #10658 (new defect)

Opened 11 months ago

Last modified 3 months ago

Prevent wxStaticBox from being used as a parent

Reported by: dememax Owned by:
Priority: normal Milestone:
Component: GUI-all Version: 2.8.9
Keywords: crash wxpython Cc: cdleary@…
Blocked By: Patch: no
Blocking:

Description

This simple produces segfalut on Linux, on MS Windows XP it crashes too.

import wx

class MyFrame(wx.Frame):
    def __init__(
            self, parent, ID, title, pos=wx.DefaultPosition,
            size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
            ):

        wx.Frame.__init__(self, parent, ID, title, pos, size, style)
        sizer = wx.BoxSizer(wx.VERTICAL)
        somebox = wx.StaticBox(self, -1, "Some");
        wx.StaticText(somebox, -1, "Comment this problematic ctrl")
        sizer.Add(somebox, 0, wx.EXPAND)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def OnCloseWindow(self, event):
        self.Destroy()

if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, -1, "aaa")
    app.SetTopWindow(frame)
    frame.Show()
    app.MainLoop()

Comment the line with StaticText and all works fine.
This line looks incorrect but it's not a reason to do a crash for running scripting environment (do anything - python exception, message box, but not a segfault).

Versions:
Gentoo Linux
Linux dememax-laptop 2.6.27-gentoo-r8 #2 SMP Fri Jan 23 13:42:35 MSK 2009 i686 Intel(R) Core(TM)2 CPU T5600 @ 1.83GHz GenuineIntel GNU/Linux
dev-lang/python: 2.5.2-r7
x11-libs/gtk+: 2.14.7-r2
x11-libs/wxGTK: 2.8.9.1-r3
dev-python/wxpython: 2.8.9.1-r2

Change History

Changed 10 months ago by robind

  • component changed from wxPython to GUI-all
  • summary changed from Incorrect creation of wx.StaticText crashes an application to Prevent wxStaticBox from being used as a parent

Hmm... I thought we had an assert that would catch this, but I don't see it currently, if there is one somewhere that I'm not looking then you should get it as a Python exception if your wxPython was built correctly.

Anyway, StaticBoxes can not have children. Make your text be a sibling of the static box and use a wx.StaticBoxSizer to position it inside the box.

I'll leave this ticket open to be a reminder to put an assert in there, or some other way to prevent the static box from being used as a parent.

Changed 10 months ago by frm

There is an assert catching this problem in wincmn.cpp at line 228 in wxWindowBase::CreateBase... maybe however adding:

    virtual void AddChild(wxWindowBase* WXUNUSED(child))
    {
        wxFAIL_MSG("Do not add child windows to wxStaticBox; see wxStaticBox docs");
    }

in wxStaticBoxBase could help, too...

Changed 3 months ago by cdleary

  • cc cdleary@… added
Note: See TracTickets for help on using tickets.