Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Preference pain!

Preference pain!
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 27, 2003, 07:23 PM
 
I'm having trouble with a preference pane. It has its own controller (PreferenceController) and its own nib. The problem is that the app crashes with a Signal 10 (SIGBUS) error if the panel is opened a second time. It crashes immediately after the window shows up on the screen. It is launched with the following code from the main controller object:

Code:
-(IBAction)showPreferencePanel:(id)sender { if (!preferenceController) { NSLog(@"new pref control"); preferenceController=[[PreferenceController alloc] init]; } [preferenceController showWindow:self]; }


The actual PreferenceController is pretty basic and mainly just sets some user defaults:

Code:
#import "PreferenceController.h" #import "FMController.h" #import "Machine.h" @implementation PreferenceController -(id)init { self=[super initWithWindowNibName:@"Preferences"]; NSLog(@"pref init"); return self; } -(void)windowDidLoad { NSLog(@"prefpane windowdidload begin"); NSUserDefaults *defaults; defaults=[NSUserDefaults standardUserDefaults]; [teamIDField setStringValue:[defaults objectForKey:@"teamIDKey"]]; [userIDField setStringValue:[defaults objectForKey:@"userIDKey"]]; NSLog(@"prefpane windowdidload finished user and team"); [logDirectoryField setStringValue:[defaults objectForKey:@"logFileDirectoryKey"]]; [secondLogDirectoryField setStringValue:[defaults objectForKey:@"secondLogFileDirectoryKey"]]; NSLog(@"prefpane windowdidload finishedlog files"); [refreshTimeField setIntValue:[[defaults objectForKey:@"refreshTimeKey"] intValue]/60]; if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"toggleButtonStateKey"] isEqualToString:@"NO"]) { [toggleButton setState:NSOffState]; } else { [toggleButton setState:NSOnState]; } NSLog(@"prefpane windowdidload end"); } -(IBAction)openLogFile:(id)sender { NSOpenPanel *oPanel = [NSOpenPanel openPanel]; NSString *result; NSString *logFile; if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"logFileDirectoryKey"] isEqualToString:@"Not Entered"]) { [oPanel setAllowsMultipleSelection:NO]; result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:nil]; } else { [oPanel setAllowsMultipleSelection:NO]; result = [oPanel runModalForDirectory:[[NSUserDefaults standardUserDefaults] objectForKey:@"logFileDirectoryKey"] file:nil types:nil]; } if (result !=NSCancelButton) { logFile=[[oPanel filenames] objectAtIndex:0]; [[NSUserDefaults standardUserDefaults] setObject:[logFile stringByDeletingLastPathComponent] forKey:@"logFileDirectoryKey"]; [logDirectoryField setStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"logFileDirectoryKey"]]; [[NSNotificationCenter defaultCenter] postNotificationName:@"logFilesChanged" object:self]; } } -(IBAction)refreshToggleButtonPressed:(id)sender { if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"toggleButtonStateKey"] isEqualToString:@"NO"]) { [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"toggleButtonStateKey"]; [toggleButton setState:NSOnState]; } else { [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"toggleButtonStateKey"]; [toggleButton setState:NSOffState]; } } -(IBAction)refreshTimeChanged:(id)sender { [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:[refreshTimeField intValue]*60] forKey:@"refreshTimeKey"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"timerChanged" object:self]; } -(IBAction)openSecondLogFile:(id)sender { NSOpenPanel *oPanel = [NSOpenPanel openPanel]; NSString *result; NSString *secondLogFile; if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"secondLogFileDirectoryKey"] isEqualToString:@"Not Entered"]) { [oPanel setAllowsMultipleSelection:NO]; result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:nil]; } else { [oPanel setAllowsMultipleSelection:NO]; result = [oPanel runModalForDirectory:[[NSUserDefaults standardUserDefaults] objectForKey:@"secondLogFileDirectoryKey"] file:nil types:nil]; } if (result !=NSCancelButton) { secondLogFile=[[oPanel filenames] objectAtIndex:0]; [[NSUserDefaults standardUserDefaults] setObject:[secondLogFile stringByDeletingLastPathComponent] forKey:@"secondLogFileDirectoryKey"]; [secondLogDirectoryField setStringValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"secondLogFileDirectoryKey"]]; [[NSNotificationCenter defaultCenter] postNotificationName:@"logFilesChanged" object:self]; } } -(IBAction)changeTeamID:(id)sender { [[NSUserDefaults standardUserDefaults] setObject:[teamIDField stringValue] forKey:@"teamIDKey"]; } -(IBAction)changeUserID:(id)sender{ [[NSUserDefaults standardUserDefaults] setObject:[userIDField stringValue] forKey:@"userIDKey"]; } @end
This is really starting to frustrate me as I have no idea how to proceed. I'm thinking this might be my first foray into the debugger which I've never really used, so any suggestions on how to get started using it to track down my problem would be appreciated.

kman
     
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
May 28, 2003, 02:33 PM
 
Maybe it has something to do with you not deallocating? Just a guess...

Steve W
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 28, 2003, 02:44 PM
 
Originally posted by techtrucker:
Maybe it has something to do with you not deallocating? Just a guess...

Steve W
I was thinking I needed to add in a dealloc method, but it isn't clear to me that is the cause of the problem. I don't think the object gets deallocated when the pane is closed. I think it just gets moved off screen. I'll put it in there because it 'should' be in there, but I have my doubts if it will fix the problem. Thanks for the advice though!

Any other ideas or help getting started with the debugger?

kman
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 28, 2003, 04:42 PM
 
WOW!!!!

The debugger rules!

I put in a breakpoint at [myObject showWindow:] which seemed to be the last method being called prior to the crash. I then ran it with the debugger on and I gave me an error and showed me the line where it was occuring. Turned out to be a drawRect method in a custom NSView. I had released the NSBezierPath at the wrong point so when it went to redraw the view as it put up the pref pane, it would crash. I NEVER would have looked there.

I'm so excited to have learned about this powerful tool. I can't believe I have been using NSLogs to debug my code all this time. They still have their place, but I'm a debug devotee now.

kman
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:36 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2