PyObjC + wxPython causes crash when application closes / cleans up

Issue #68 new
Hok Shun Poon
created an issue

I've tried to use PyObjc with a simple wxPython application and found that while they sort of do work together, the application crashes at the end when closing.

See this SO question for details

import wx

def register_protocol_handlers():
    """Register the URL scheme listener using PyObjC"""
        # Let's just do something DEAD simple.
        from Foundation import NSBundle
    except ImportError:
        print("Can't even get here.")

class MyFrame(wx.Frame):
    This is MyFrame.  It just shows a few controls on a wxPanel,
    and has a simple menu.
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title,
                          pos=(150, 150), size=(350, 200))

        # Create the menubar
        menuBar = wx.MenuBar()

        # and a menu
        menu = wx.Menu()

        # add an item to the menu, using \tKeyName automatically
        # creates an accelerator, the third param is some help text
        # that will show up in the statusbar
        menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")

        # bind the menu event to an event handler
        self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)

        # and put the menu on the menubar
        menuBar.Append(menu, "&File")


        # Now create the Panel to put the other controls on.
        panel = wx.Panel(self)

        # and a few controls
        text = wx.StaticText(panel, -1, "Hello World!")
        text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
        btn = wx.Button(panel, -1, "Close")
        funbtn = wx.Button(panel, -1, "Just for fun...")

        # bind the button events to handlers
        self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
        self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)

        # Use a sizer to layout the controls, stacked vertically and with
        # a 10 pixel border around each
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(text, 0, wx.ALL, 10)
        sizer.Add(btn, 0, wx.ALL, 10)
        sizer.Add(funbtn, 0, wx.ALL, 10)

    def OnTimeToClose(self, evt):
        """Event handler for the button click."""
        print "See ya later!"

    def OnFunButton(self, evt):
        """Event handler for the button click."""
        print "Having fun yet?"

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, "Simple wxPython App")
        print "Print statements go to this stdout window by default."
        return True

app = MyApp(redirect=True)

The crash looks like:

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010

VM Regions Near 0x10:
    __TEXT                 000000010dddd000-000000010dddf000 [    8K] r-x/rwx SM=COW  /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/Resources/

Thread 0 Crashed:: Dispatch queue:
0   libobjc.A.dylib                 0x00007fff921a3209 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 425
1        0x00007fff8c6ddd72 _CFAutoreleasePoolPop + 34
2            0x00007fff8e15ffbd -[NSAutoreleasePool release] + 154
3   libwx_osx_cocoau-2.9.dylib      0x000000010e6c2a9e wxApp::~wxApp() + 54
4                       0x000000010e38f7c3 wxPyApp::~wxPyApp() + 83
5   libwx_osx_cocoau-2.9.dylib      0x000000010e5e164c wxEntryCleanup() + 72
6                       0x000000010e3f4c44 _wrap_App_CleanUp + 52
7   org.python.python               0x000000010de68fdc PyEval_EvalFrameEx + 14225
8   org.python.python               0x000000010de65721 PyEval_EvalCodeEx + 1638
9   org.python.python               0x000000010de0ccaa function_call + 336
10  org.python.python               0x000000010ddef4fd PyObject_Call + 101
11  org.python.python               0x000000010de6b274 PyEval_CallObjectWithKeywords + 93
12  org.python.python               0x000000010de832f4 Py_Finalize + 184
13  org.python.python               0x000000010de94635 Py_Main + 3209
14  libdyld.dylib                   0x00007fff87fab7e1 start + 1```

Why does this happen?

Comments (3)

  1. Log in to comment