Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 626229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:23:44+00:00 2026-05-13T19:23:44+00:00

I’m writing a preference pane to control a script I created, and I want

  • 0

I’m writing a preference pane to control a script I created, and I want to show a sheet on first launch so the user can tell the pane where they installed the script. The sheet appears fine, the problem is that it appears right after you click the button for my pane. This causes System Preferences to Segmentation Fault immediately.

I’m using the command to show the sheet inside awakeFromNib, which may have something to do with it, but I can’t get anything inside of mainViewDidLoad to actually execute. Any ideas on what I can do?

Code:

- (void) awakeFromNib
{
NSLog(@"hi");
[sheetController setParentWindow:[NSApp mainWindow]];
BashScript *script = [[BashScript alloc] init];
if (![script loadScriptFromLocation:[self retrieveScriptLocation]])
{
    NSLog(@"Error loading script.");
}
else {
    [advancedEditor setString:[script getScript]];
}
}


- (NSString*) retrieveScriptLocation
{
NSUserDefaults *preferences = [[NSUserDefaults standardUserDefaults] retain];
NSString *location = [preferences stringForKey:@"scriptLocation"];
if (location != nil)
{
    return location;
}
else
{
    return [self askForScript];
}
}

- (NSString*) askForScript
{
[sheetController openSheet:nil];
}

EDIT: Here’s the stack trace from the crash: http://files.spherecat1.com/prefpanestacktrace.txt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:23:44+00:00Added an answer on May 13, 2026 at 7:23 pm

    The stack trace reveals the cause of your crash:

    - (void) awakeFromNib
    {
      if (![script loadScriptFromLocation:[self retrieveScriptLocation]])
    
    - (NSString*) retrieveScriptLocation
    {
      return [self askForScript];
    
    - (NSString*) askForScript
    {
      [sheetController openSheet:nil];
    }
    

    You haven’t returned a value from this method that you’ve declared as returning a value. The compiler should be warning you about this.

    The crash happens because the method returns with effectively random bytes (possibly a valid object pointer, possibly not) where the return value should be. You can tell that this return value was supposed to be a string by looking at the attempted message in the stack trace:

    Application Specific Information:
    objc_msgSend() selector name: getFileSystemRepresentation:maxLength:

    That’s an NSString method, so something—in this case, the implementation behind -[NSData initWithContentsOfFile:] and -[NSFileManager contentsAtPath:]—tried to treat the address as that of an NSString. It isn’t, which is what caused the crash, and is because you didn’t return a string from a method where you said you would.

    Of course, you can’t just make the method return a string, because you don’t have it to return yet. You need to refactor your code to reflect the asynchronous nature of the Open panel and sheets in general. Recognize that you do not have a string yet and will not for one or more minutes; just begin the Open panel sheet and don’t attempt to load the script until it succeeds.

    In a nutshell, try to load the script, and if you don’t have a path yet, just begin the Open panel sheet and then continue on with other initialization.

    You also shouldn’t assume the Open panel will succeed. The user may cancel, especially if this is their first time opening the prefpane and they want to take a look around first. In fact, you shouldn’t show an Open panel immediately on prefpane load in the first place.

    Instead, have a file-picker view showing where the current script is, if there is one, and make clear, by its placement and explanatory text underneath it and possibly judicious application of color, that your program cannot work until the user chooses a script. Let the user choose the script and thereby enable your program whenever they’re ready to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.