Page 1 of 1

Segmentation fault (core dumped)

Posted: Mon Apr 09, 2018 5:51 am
by dineshkumar
Hi,

I am creating my own custom frame using wxpython. If I add below specified code I am getting the Segmentation fault (core dumped). If I remove wont get any issue. Please advise

If I include this code, getting the error:

Code: Select all

self.browser_panel = MainPanel(self)
        self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
        self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.closeBtn = wx.Button(self, label="X", size=(30, 30))
        self.closeBtn.Bind(wx.EVT_BUTTON, self.onClose)
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.hbox= wx.BoxSizer(wx.HORIZONTAL)
        self.hbox.Add(self.closeBtn, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.vbox.Add(self.hbox, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.SetSizer(self.vbox)
        self.vbox.SetSizeHints(self)
        self.sizer.Add(self.closeBtn, 0, wx.ALIGN_RIGHT | wx.ALL)
        self.sizer.Add(self.browser_panel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
original code:

Code: Select all

class MainFrame(wx.Frame):

    def __init__(self, url):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                          title='wxPython example')
        self.browser = None
        print(url)
        # Must ignore X11 errors like 'BadWindow' and others by
        # installing X11 error handlers. This must be done after
        # wx was intialized.
        if LINUX:
            WindowUtils.InstallX11ErrorHandlers()

        global g_count_windows
        g_count_windows += 1
        self.SetFullScreen()
        self.browser_panel = MainPanel(self)
        self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
        self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.closeBtn = wx.Button(self, label="X", size=(30, 30))
        self.closeBtn.Bind(wx.EVT_BUTTON, self.onClose)
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.hbox= wx.BoxSizer(wx.HORIZONTAL)
        self.hbox.Add(self.closeBtn, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.vbox.Add(self.hbox, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.SetSizer(self.vbox)
        self.vbox.SetSizeHints(self)
        self.sizer.Add(self.closeBtn, 0, wx.ALIGN_RIGHT | wx.ALL)
        self.sizer.Add(self.browser_panel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

class MainPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.mainpanel = wx.Panel(self) 
        sizer = wx.BoxSizer(wx.VERTICAL) 
        closeBtn = wx.Button(self, label="X", size=(30, 30))
        closeBtn.Bind(wx.EVT_BUTTON, self.onClose)
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox= wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(closeBtn, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        vbox.Add(hbox, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.SetSizer(vbox)
        vbox.SetSizeHints(self)
        sizer.Add(closeBtn, 0, wx.ALIGN_RIGHT | wx.ALL)
        self.SetSizer(sizer)
        self.Bind(wx.EVT_SET_FOCUS, self.onFocus)

    def onClose(self, event):
        try:
          if "file://" in self.url:
             sys.exit(0)
          else:
             #logging.info("panel 1 Close Button clicked") 
             self.Hide()
             self.GetParent().panel_two.ShowYourself()
        except Exception as ex:
          #ESSBLog.ValidationError(ex)
          print ex

    def onFocus(self, event):
        #self.Raise()
        #logging.info("panel 1 Raised")
        pass

    def ShowYourself(self):
        #self.Raise()
        #logging.info("panel 1 show")
        self.Show()

Re: Segmentation fault (core dumped)

Posted: Mon Apr 09, 2018 6:36 am
by catalin
This is not the way to ask a question. You need to simplify your code before asking such questions. And it will surely lead to finding the cause of the crash.

In this case you are adding closeBtn to 2 sizers, which is a guaranteed cause of crash. You also call self.SetSizer for 2 sizers.

Re: Segmentation fault (core dumped)

Posted: Mon Apr 09, 2018 7:38 am
by dineshkumar
Will follow your advice for further post. Thanks for advice