3

I'm have a routine based on code found on this forum:

+ (FSRef)useOpenFileToGetFSRef:(NSString **)fileName requiredFileType: (NSString*) requiredFileType
{
     FSRef fileFSRef;
    NSArray* fileTypes = [[NSArray alloc] initWithObjects:requiredFileType, nil];

    //http://stackoverflow.com/questions/11815784/objective-c-nsopenpanel-get-filename
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];
    [openDlg setFloatingPanel:YES];
    [openDlg setCanChooseDirectories:NO];
    [openDlg setCanChooseFiles:YES];
    [openDlg setAllowsMultipleSelection:YES];
    [openDlg setAllowedFileTypes:fileTypes];

    if ( [openDlg runModal] == NSOKButton )  //<== CRASHES ON CALL TO runModal
    {
        NSArray* filePaths = [openDlg URLs];
        //only getting 1st file
        NSURL *fileUrl = [filePaths objectAtIndex:0];

        *fileName = [fileUrl path];
        CFURLGetFSRef((CFURLRef)fileUrl, &fileFSRef);
    }

    return fileFSRef;
}

The app repeatably crases on the call to runModel:

NSOpenPanel runModal anomaly

What could explain this?

Thanks very much in advance to all for any info.

System info: OS X 10.8.4. Compiled using ARC.

VikR
  • 4,818
  • 8
  • 51
  • 96
  • What is the exception? – allprog Jul 04 '13 at 19:50
  • According to your image the throw is occurring in another thread, quicklook.pluginload, and not directly in `runModal` itself. What are you doing in the dialog? Do you have custom quicklook plugins installed? – CRD Jul 04 '13 at 20:08
  • I don't yet see a notice of the name of the exception. – VikR Jul 04 '13 at 20:36
  • I'm not running any custom quicklook plugins. – VikR Jul 04 '13 at 20:36
  • What could be possibly be causing a crash in the quicklook thread? – VikR Jul 04 '13 at 21:02
  • I created a new project and copied into it the code that is crashing. In the new project, it doesn't crash. But no other code is called. Is it possible that my project file is corrupted? – VikR Jul 05 '13 at 08:41
  • I copied everything into a new project file, and the anomaly disappeared. – VikR Jul 05 '13 at 09:14

3 Answers3

7

I actually think you had a breakpoint on all exceptions. I just ran into this and was looking for why. I ran into this post, but then found the following.

NSOpenPanel crashes when debugging with Xcode 4.5.1

When you recreated the project, the breakpoints got reset.

Community
  • 1
  • 1
Mobile Ben
  • 7,121
  • 1
  • 27
  • 43
  • I only just saw this comment, months later. Very interesting! So are exceptions normal in open & save dialog boxes? – VikR Jan 24 '14 at 03:35
0

It looks like there was some anomaly in the project file. I copied all the source files and xib files to a new project, and after that NSOpenPanel runModal worked as expected.

VikR
  • 4,818
  • 8
  • 51
  • 96
0

Had a similar problem. I had not been storing all of the project files (same code worked perfectly on another machine). I removed them one-by-one, no effect. Removed DerivedData directory and no effect.

lappy:vStacks ndunn$ hg st . ? StacksGui3.xcodeproj/project.xcworkspace/xcuserdata/ndunn.xcuserdatad/UserInterfaceState.xcuserstate ? StacksGui3.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcschemes/StacksGui3.xcscheme ? vStacks.xcodeproj/project.xcworkspace/xcuserdata/ndunn.xcuserdatad/UserInterfaceState.xcuserstate ? vStacks.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist ? vStacks.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcschemes/vStacks.xcscheme ? vStacks.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcschemes/xcschememanagement.plist

I was about to do what you did, but I ended up:
1 - deleting my vStacks.xcodeproj and source
2 - creating another one with the same name
3 - deleted the new one
4 - recovered the entire project from source control.

Note: Not sure if steps 2 and 3 are necessary, but 1 and 4 certainly are.

Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38
Nathan Dunn
  • 447
  • 5
  • 16