Very Simple Demo: Modal Dialog causes later Modal Session to Crash
Very Simple Demo: Modal Dialog causes later Modal Session to Crash
- Subject: Very Simple Demo: Modal Dialog causes later Modal Session to Crash
- From: Jerry Krinock <email@hidden>
- Date: Wed, 15 Sep 2010 18:07:36 -0700
Last week I found that an app would crash if I displayed a modal dialog in -applicationWillFinishLaunching (note: *Will*), *and* *then* ran a modal session on a window in -applicationDidFinishLaunching: (note: *Did*).
I've now reproduced it in a very simple demo, shown below. Why does this crash?
Thanks,
Jerry Krinock
@implementation MyAppDelegate
- (void)applicationWillFinishLaunching:(NSNotification*)aNotification {
NSRunAlertPanel(@"Hello",
@"A crash is coming soon.",
@"OK",
nil,
nil) ;
}
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 200, 200)
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO] ;
// Crash here…
NSModalSession session = [NSApp beginModalSessionForWindow:window] ;
[NSApp runModalSession:session] ;
}
@end
***** Notes *****
• If you don't run the NSRunAlertPanel(), then there is no crash
• If you move the NSRunAlertPanel() from -applicationWillFinishLaunching:
to -applicationDidFinishLaunching:, then there is no crash
• Running Mac OS X 10.6.4, Intel-32
• Same crash compiling with either SDK Mac OS X 10.5 or 10.6
***** Console Output *****
Kind of looks like something messaged the GUI from a non-main thread. But 80f is the main thread.
Running…
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x30e200 of class NSCFString autoreleased with no pool in place - just leaking
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x30e320 of class NSCFString autoreleased with no pool in place - just leaking
[20208:80f] *** Assertion failure in -[NSApplication run], /SourceCache/AppKit/AppKit-1038.32/AppKit.subproj/NSApplication.m:2579
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x141d50 of class NSCFString autoreleased with no pool in place - just leaking
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x3211d0 of class NSException autoreleased with no pool in place - just leaking
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x30f3c0 of class _NSCallStackArray autoreleased with no pool in place - just leaking
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x310420 of class _NSCallStackArray autoreleased with no pool in place - just leaking
[20208:80f] An uncaught exception was raised
[20208:80f] NSApp with wrong _running count
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x3106f0 of class NSCFString autoreleased with no pool in place - just leaking
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x1008400 of class NSCFString autoreleased with no pool in place - just leaking
[20208:80f] *** __NSAutoreleaseNoPool(): Object 0x310390 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
[20208:80f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSApp with wrong _running count'
*** Call stack at first throw:
(
0 CoreFoundation 0x98b9bbba __raiseError + 410
1 libobjc.A.dylib 0x9957f509 objc_exception_throw + 56
2 CoreFoundation 0x98b9b8e8 +[NSException raise:format:arguments:] + 136
3 Foundation 0x958f3dc3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 AppKit 0x90fd2332 -[NSApplication run] + 268
5 AppKit 0x90fca5ed NSApplicationMain + 574
6 AppWillFinishCrashing 0x00001c84 main + 30
7 AppWillFinishCrashing 0x00001c3a start + 54
)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden