When trying to open a directory the second or third time I get a EXC_BAD_ACCESS crash when I press the open button. However, it doesn't crash the first time or sometimes the second time, but always the third time.
I am trying to fix code written by someone else, and am new to Objective-C, so apologies if this is a simple problem.
The problem occurs during the runModalForDirectory
Below is the previous code in the function
I am trying to fix code written by someone else, and am new to Objective-C, so apologies if this is a simple problem.
The problem occurs during the runModalForDirectory
Code:
if ( [oPanel runModalForDirectory:nil file:nil types:fileTypes] == NSOKButton )
Below is the previous code in the function
Code:
NSString* fname;
// printf("loading files\n");
NSArray *fileTypes = [NSArray arrayWithObjects:@"asc", nil];
// Create the File Open Panel class.
NSOpenPanel* oPanel = [NSOpenPanel openPanel];
[oPanel setCanChooseDirectories:YES];
[oPanel setCanChooseFiles:NO];
[oPanel setCanCreateDirectories:YES];
[oPanel setAllowsMultipleSelection:NO];
[oPanel setAlphaValue:0.95];
[oPanel setTitle:@"Select a directory to open"];
// Display the dialog. If the OK button was pressed, process the files.
if ( [oPanel runModalForDirectory:nil file:nil types:fileTypes] == NSOKButton )
{
// Get an array containing the full filenames of all files and directories selected.
fname = [oPanel filename];
}