Bizarre Crash Handling Auxiliary Window
Bizarre Crash Handling Auxiliary Window
- Subject: Bizarre Crash Handling Auxiliary Window
- From: Christopher Gernon <email@hidden>
- Date: Sun, 15 Jun 2003 10:22:27 -0400
I'm a beginning Cocoa programmer just starting my first "real" project. I'm
running into a problem handling an auxiliary window (i.e. a window not
intantiated at application launch). For good modular program design, I want
my preferences window to be loaded from a nib when the user needs it and
then deallocated when the user is done with it.
Here's the problem: It allocates and displays fine. When the user clicks the
"Cancel" button or hits Esc, its key equivalent, it exits fine. When the
user clicks the "OK" button, it exits fine. When the user hits Return (the
"OK" button's key equivalent) ... "DCTest01 has exited due to signal 10
(SIGBUS)." WTF?!?!?!
Stepping through it in debug, it seems to get through my code fine, no
problems in the "goodbye" function or the dealloc, but then it steps out
into "NSPopAutoreleasePool" and I get 175 lines of:
[Switching to process 2050 thread 0xb03]
[Switching to process 2050 thread 0x1203]
[Switching to process 2050 thread 0xb03]
[Switching to process 2050 thread 0xb03]
[Switching to process 2050 thread 0x1203]
[Switching to process 2050 thread 0xb03]
... followed by 'Program received signal: "EXC_BAD_ACCESS".' (The trace
stops in "objc_msgSend", so it may be crashing either in that or in
"NSPopAutoreleasePool" - not sure how to read it.)
Any idea what could be going on? My guess is some subtle memory management
mistake, but it seems really strange that it works fine when the user CLICKS
the OK button, but not when the key equivalent is used.
Here's my DCPrefsController.m - as you can see, it's pretty much
stubbed-out, boilerplate stuff (I haven't even put any actual
preference-handling code in it yet), which makes me really scratch my head.
It gets invoked by the main controller object with:
[[DCPrefsController sharedInstance] showWindow:nil];
Any thoughts anyone has would be greatly appreciated! :)
Thanks,
Chris
--------------------------------------------------------------------------
#import "DCPrefsController.h"
@implementation DCPrefsController
- (void)awakeFromNib
{
[[self window] makeKeyAndOrderFront:self];
[defaultsUsernameField selectText:self];
}
- (void)dealloc
{
NSLog(@"Deallocating DCPrefsController object\n");
[super dealloc];
}
// --------------- sharedInstance creator/returner
static DCPrefsController *sharedInstance = nil;
+ (DCPrefsController *)sharedInstance
{
if(sharedInstance == nil)
{
sharedInstance = [[DCPrefsController alloc]
initWithWindowNibName:@"Preferences"];
NSLog(@"initialized DCPrefsController object\n");
}
return(sharedInstance);
}
// --------------- exit/release on OK or cancel
- (void)goodbye
{
sharedInstance = nil;
[[self window] performClose:self];
[self autorelease];
// [self release]; // Maybe this would work better than autorelease?
}
// --------------- Cancel/save buttons from window
- (IBAction)prefsCancel:(id)sender
{
[self goodbye];
}
- (IBAction)prefsSave:(id)sender
{
[self goodbye];
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.