Thread: [Pyobjc-dev] Crash when closing all documents
Brought to you by:
ronaldoussoren
From: Daniel M. <mil...@gm...> - 2009-11-19 00:48:38
|
I'm having problems calling the selector provided by NSDocumentController .closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo: Here's my code: class DocumentController(NSDocumentController): ... def closeAllDocumentsWithDelegate_didCloseAllSelector_contextInfo_( self, delegate, selector, context): def callback(result): log.debug("%s.%s(%s, %s, %s)", delegate, selector, self, result, context) perform_selector(delegate, selector, self, result, context) saver = DocumentSavingDelegate.alloc().\ initWithDocuments_callback_context_( self.controller.iter_dirty_documents(), callback, context) saver.save_next_document() def perform_selector(delegate, selector, *args): # sel = selector.replace(":", "_") # HACK # getattr(delegate, sel)(*args) inv = NSInvocation.invocationWithMethodSignature_( delegate.methodSignatureForSelector_(selector)) inv.setTarget_(delegate) inv.setSelector_(selector) for i, arg in enumerate(args): inv.setArgument_atIndex_(arg, i + 2) inv.invoke() Here's the debug message and stack trace I get when the callback gets called: DEBUG <DocumentController: 0x114ab0>._documentController:shouldTerminate:context: (<DocumentController: 0x114ab0>, True, 1401200) 2009-11-18 19:32:36.137 EditXTDev[51404:60b] *** ObjC exception 'NSUncaughtSystemExceptionException' (reason: 'Uncaught system exception: signal 10') discarded Stack trace (most recent call last): -[NSMenu _performActionWithHighlightingForItemAtIndex:] (in AppKit) + 49 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] (in AppKit) + 174 -[NSMenuItem _corePerformAction] (in AppKit) + 435 -[NSApplication sendAction:to:from:] (in AppKit) + 112 -[NSApplication terminate:] (in AppKit) + 519 -[NSApplication _shouldTerminate] (in AppKit) + 669 -[NSApplication sendEvent:] (in AppKit) + 6431 -[NSWindow sendEvent:] (in AppKit) + 5549 -[NSControl mouseDown:] (in AppKit) + 812 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] (in AppKit) + 524 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] (in AppKit) + 1808 -[NSCell _sendActionFrom:] (in AppKit) + 169 -[NSControl sendAction:to:] (in AppKit) + 108 -[NSApplication sendAction:to:from:] (in AppKit) + 112 -[NSAlert buttonPressed:] (in AppKit) + 392 -[NSApplication endSheet:returnCode:] (in AppKit) + 349 -[NSAlert didEndSheet:returnCode:contextInfo:] (in AppKit) + 133 -[NSWindow orderOut:] (in AppKit) + 50 -[NSWindow orderWindow:relativeTo:] (in AppKit) + 105 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] (in AppKit) + 1836 -[NSWindow(NSSheets) _orderOutRelativeToWindow:] (in AppKit) + 123 -[NSMoveHelper(NSSheets) _closeSheet:andMoveParent:] (in AppKit) + 463 -[NSWindow(NSSheets) _detachSheetWindow] (in AppKit) + 501 -[NSNotificationCenter postNotificationName:object:] (in Foundation) + 56 -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation) + 128 _CFXNotificationPostNotification (in CoreFoundation) + 186 __CFXNotificationPost (in CoreFoundation) + 905 _nsnote_callback (in Foundation) + 176 ffi_closure_SYSV (in _objc.so) + 196 method_stub (in _objc.so) + 1687 PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) function_call (in libpython2.6.dylib) (funcobject.c:524) PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3917) PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) pysel_call (in _objc.so) + 1264 PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) function_call (in libpython2.6.dylib) (funcobject.c:524) PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3917) PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) pysel_call (in _objc.so) + 1264 PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) function_call (in libpython2.6.dylib) (funcobject.c:524) PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3802) PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3802) PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3917) PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) objcsel_call (in _objc.so) + 230 PyObjCFFI_Caller (in _objc.so) + 2709 ffi_call (in _objc.so) + 147 .LCFI1 (in _objc.so) (x86-darwin.S:84) -[NSInvocation invoke] (in CoreFoundation) + 136 __invoking___ (in CoreFoundation) + 29 -[NSDocumentController(NSInternal) _documentController:shouldTerminate:context:] (in AppKit) + 321 0xffffffff _sigtramp (in libSystem.B.dylib) + 43 NSExceptionHandlerUncaughtSignalHandler (in ExceptionHandling) + 65 Am I doing something wrong or is this a bug? Versions: Mac OS X 10.6 Python 2.6.2 PyObjC 2.2b2 Thanks in advance for any help you can provide. ~ Daniel |
From: Ronald O. <ron...@ma...> - 2009-11-19 08:18:37
Attachments:
smime.p7s
|
On 19 Nov, 2009, at 1:48, Daniel Miller wrote: > I'm having problems calling the selector provided by > > NSDocumentController.closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo: > > Here's my code: > > class DocumentController(NSDocumentController): > ... > def closeAllDocumentsWithDelegate_didCloseAllSelector_contextInfo_( > self, delegate, selector, context): > def callback(result): > log.debug("%s.%s(%s, %s, %s)", > delegate, selector, self, result, context) > perform_selector(delegate, selector, self, result, context) > saver = DocumentSavingDelegate.alloc().\ > initWithDocuments_callback_context_( > self.controller.iter_dirty_documents(), callback, context) > saver.save_next_document() > > def perform_selector(delegate, selector, *args): > # sel = selector.replace(":", "_") # HACK > # getattr(delegate, sel)(*args) > inv = NSInvocation.invocationWithMethodSignature_( > delegate.methodSignatureForSelector_(selector)) > inv.setTarget_(delegate) > inv.setSelector_(selector) > for i, arg in enumerate(args): > inv.setArgument_atIndex_(arg, i + 2) > inv.invoke() > > Here's the debug message and stack trace I get when the callback gets called: > > DEBUG <DocumentController: 0x114ab0>._documentController:shouldTerminate:context:(<DocumentController: 0x114ab0>, True, 1401200) > 2009-11-18 19:32:36.137 EditXTDev[51404:60b] *** ObjC exception 'NSUncaughtSystemExceptionException' (reason: 'Uncaught system exception: signal 10') discarded > Stack trace (most recent call last): > -[NSMenu _performActionWithHighlightingForItemAtIndex:] (in AppKit) + 49 > -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] (in AppKit) + 174 > -[NSMenuItem _corePerformAction] (in AppKit) + 435 > -[NSApplication sendAction:to:from:] (in AppKit) + 112 > -[NSApplication terminate:] (in AppKit) + 519 > -[NSApplication _shouldTerminate] (in AppKit) + 669 > -[NSApplication sendEvent:] (in AppKit) + 6431 > -[NSWindow sendEvent:] (in AppKit) + 5549 > -[NSControl mouseDown:] (in AppKit) + 812 > -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] (in AppKit) + 524 > -[NSCell trackMouse:inRect:ofView:untilMouseUp:] (in AppKit) + 1808 > -[NSCell _sendActionFrom:] (in AppKit) + 169 > -[NSControl sendAction:to:] (in AppKit) + 108 > -[NSApplication sendAction:to:from:] (in AppKit) + 112 > -[NSAlert buttonPressed:] (in AppKit) + 392 > -[NSApplication endSheet:returnCode:] (in AppKit) + 349 > -[NSAlert didEndSheet:returnCode:contextInfo:] (in AppKit) + 133 > -[NSWindow orderOut:] (in AppKit) + 50 > -[NSWindow orderWindow:relativeTo:] (in AppKit) + 105 > -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] (in AppKit) + 1836 > -[NSWindow(NSSheets) _orderOutRelativeToWindow:] (in AppKit) + 123 > -[NSMoveHelper(NSSheets) _closeSheet:andMoveParent:] (in AppKit) + 463 > -[NSWindow(NSSheets) _detachSheetWindow] (in AppKit) + 501 > -[NSNotificationCenter postNotificationName:object:] (in Foundation) + 56 > -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation) + 128 > _CFXNotificationPostNotification (in CoreFoundation) + 186 > __CFXNotificationPost (in CoreFoundation) + 905 > _nsnote_callback (in Foundation) + 176 > ffi_closure_SYSV (in _objc.so) + 196 > method_stub (in _objc.so) + 1687 > PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) > function_call (in libpython2.6.dylib) (funcobject.c:524) > PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) > PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3917) > PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) > pysel_call (in _objc.so) + 1264 > PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) > function_call (in libpython2.6.dylib) (funcobject.c:524) > PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) > PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3917) > PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) > pysel_call (in _objc.so) + 1264 > PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) > function_call (in libpython2.6.dylib) (funcobject.c:524) > PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) > PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3802) > PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) > PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3802) > PyEval_EvalCodeEx (in libpython2.6.dylib) (ceval.c:2968) > PyEval_EvalFrameEx (in libpython2.6.dylib) (ceval.c:3917) > PyObject_Call (in libpython2.6.dylib) (abstract.c:2492) > objcsel_call (in _objc.so) + 230 > PyObjCFFI_Caller (in _objc.so) + 2709 > ffi_call (in _objc.so) + 147 > .LCFI1 (in _objc.so) (x86-darwin.S:84) > -[NSInvocation invoke] (in CoreFoundation) + 136 > __invoking___ (in CoreFoundation) + 29 > -[NSDocumentController(NSInternal) _documentController:shouldTerminate:context:] (in AppKit) + 321 > 0xffffffff > _sigtramp (in libSystem.B.dylib) + 43 > NSExceptionHandlerUncaughtSignalHandler (in ExceptionHandling) + 65 > > Am I doing something wrong or is this a bug? You seem to get a bus error, although the code looks fine at first glance. Could you create a small self-contained project that suffers from the same problem, that would make debugging a lot easier for me. Ronald |
From: Daniel M. <mil...@gm...> - 2009-11-24 03:02:02
|
> You seem to get a bus error, although the code looks fine at first > glance. Could you create a small self-contained project that suffers > from the same problem, that would make debugging a lot easier for me. Sorry for the delay in getting this to you. The example is attached. I modified the TinyTinyEdit example found in PyObjC 1.4 (and updated it slightly to use the new subclassing mechanism rather than the old NibClassBuilder.AutoBaseClass). Anyway, this little program will reproduce the error I described in the first email in this thread. Instructions to reproduce the error (execute the following at the command line after unpacking the zip file): Dependencies (This is what's on my system. Other versions may also produce the same error. 10.4 with PyObjC 1.4 did NOT produce this error to my knowlege.): Snow Leopard 10.6 Python 2.6 PyObjC 2.2b2 py2app 0.4.2 (dev?) $ cd TinyTinyEdit $ python setup.py py2app -A $ dist/TinyTinyEdit.app/Contents/MacOS/TinyTinyEdit The TinyTinyEdit window should pop up at this point. Type something in the window to make the document dirty. Then hit [Command]+Q. You should get a traceback in your terminal window. The Apple crash reporter will probably pop up as well. Context: the action you performed by following the steps outlined above simulates what would happen in my application if the user were to quit the application with unsaved documents, and then clicked "Don't Save" for each unsaved document. ~ Daniel |
From: Ronald O. <ron...@ma...> - 2009-11-24 14:15:34
Attachments:
smime.p7s
|
On 24 Nov, 2009, at 4:01, Daniel Miller wrote: >> You seem to get a bus error, although the code looks fine at first glance. Could you create a small self-contained project that suffers from the same problem, that would make debugging a lot easier for me. > > Sorry for the delay in getting this to you. The example is attached. I modified the TinyTinyEdit example found in PyObjC 1.4 (and updated it slightly to use the new subclassing mechanism rather than the old NibClassBuilder.AutoBaseClass). Anyway, this little program will reproduce the error I described in the first email in this thread. Instructions to reproduce the error (execute the following at the command line after unpacking the zip file): > > Dependencies (This is what's on my system. Other versions may also produce the same error. 10.4 with PyObjC 1.4 did NOT produce this error to my knowlege.): This is a rather annoying issue, and a instance where the Python<->ObjC bridge suddenly leaps into view to mess things up. I have committed a quick workaround in the repository, but that does require a change to your code. To call the delegate method use: getattr(delegate, selector)(self, 1, context) rather than: perform_selector(delegate, selector, self, 1, context) Some notes: * You do not have to translate the selector name into a python identifier, that's a hack but is supported behaviour (that is, if I ever change PyObjC to be stricter about the names passed to __getattr__ there will be a transition period) * This does require the very latest version of PyObjC that I'm in the process of releasing. * My fix does not work with perform_selector and I don't know if I can get that version to work without a lot of work. Ronald > > Snow Leopard 10.6 > Python 2.6 > PyObjC 2.2b2 > py2app 0.4.2 (dev?) > > $ cd TinyTinyEdit > $ python setup.py py2app -A > $ dist/TinyTinyEdit.app/Contents/MacOS/TinyTinyEdit > > The TinyTinyEdit window should pop up at this point. Type something in the window to make the document dirty. Then hit [Command]+Q. You should get a traceback in your terminal window. The Apple crash reporter will probably pop up as well. > > Context: the action you performed by following the steps outlined above simulates what would happen in my application if the user were to quit the application with unsaved documents, and then clicked "Don't Save" for each unsaved document. > > ~ Daniel > > <TinyTinyEdit.zip> > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Daniel M. <mil...@gm...> - 2009-11-27 18:50:29
|
On Nov 24, 2009, at 9:15 AM, Ronald Oussoren wrote: > On 24 Nov, 2009, at 4:01, Daniel Miller wrote: > >>> You seem to get a bus error, although the code looks fine at first >>> glance. Could you create a small self-contained project that >>> suffers from the same problem, that would make debugging a lot >>> easier for me. >> >> Sorry for the delay in getting this to you. The example is >> attached. I modified the TinyTinyEdit example found in PyObjC 1.4 >> (and updated it slightly to use the new subclassing mechanism >> rather than the old NibClassBuilder.AutoBaseClass). Anyway, this >> little program will reproduce the error I described in the first >> email in this thread. Instructions to reproduce the error (execute >> the following at the command line after unpacking the zip file): >> >> Dependencies (This is what's on my system. Other versions may also >> produce the same error. 10.4 with PyObjC 1.4 did NOT produce this >> error to my knowlege.): > > This is a rather annoying issue, and a instance where the Python<- > >ObjC bridge suddenly leaps into view to mess things up. > > I have committed a quick workaround in the repository, but that does > require a change to your code. To call the delegate method use: > > getattr(delegate, selector)(self, 1, context) > > rather than: > > perform_selector(delegate, selector, self, 1, context) > > Some notes: > > * You do not have to translate the selector name into a python > identifier, that's a hack but is supported behaviour (that is, if I > ever change PyObjC to be stricter about the names passed to > __getattr__ there will be a transition period) > > * This does require the very latest version of PyObjC that I'm in > the process of releasing. > > * My fix does not work with perform_selector and I don't know if I > can get that version to work without a lot of work. Thanks Ronald. It works now with PyObjC 2.2 ~ Daniel |