PDA

View Full Version : crash with runModalForDirectory




dbrayford
Sep 29, 2010, 01:32 PM
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

if ( [oPanel runModalForDirectory:nil file:nil types:fileTypes] == NSOKButton )


Below is the previous code in the function

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];
}



kainjow
Sep 29, 2010, 10:05 PM
When it crashes, the debugger should point you immediately to the problem.

Based on that code above the only potential problem I see is with fname. It is not initialized, so if the user cancels and the code attempts to access it, that could crash.

Otherwise, you need to post more code or just see which line of code the debugger is taking you to.

dbrayford
Sep 30, 2010, 11:05 AM
The "Program received signal: “EXC_BAD_ACCESS”." crash occurs when trying to open the window using:

[oPanel runModalForDirectory:nil file:nil types:fileTypes];


I don't understand why opening a directory for a second time would cause a crash.

below is the output from backtrace:

#0 0x145f6733 in gleRunVertexSubmitImmediate ()
#1 0x145f454a in gleLLVMArrayFunc ()
#2 0x145f454a in gleLLVMArrayFunc ()
#3 0x145f44d7 in gleSetVertexArrayFunc ()
#4 0x145cf79a in gleDrawArraysOrElements_ExecCore ()
#5 0x145d1c8d in gleDrawArraysOrElements_VBO_Exec ()
#6 0x95609aa4 in glDrawElements ()
#7 0x0001951f in -[MyFooGLView drawRect:] (self=0x1a7080, _cmd=0x962df5d0, rect={origin = {x = 406, y = 0}, size = {width = 275, height = 5}}) at /Users/kinglab/Desktop/C3.3.5/MyFooGLView.m:2442
#8 0x97779bf8 in -[NSView _drawRect:clip:] ()
#9 0x97777469 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#10 0x97777e9f in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#11 0x97777e9f in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#12 0x97776987 in -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#13 0x977734ab in -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()
#14 0x976b3e7b in -[NSView displayIfNeeded] ()
#15 0x976b3a29 in -[NSWindow displayIfNeeded] ()
#16 0x976b384c in _handleWindowNeedsDisplay ()
#17 0x95c31772 in __CFRunLoopDoObservers ()
#18 0x95c32acc in CFRunLoopRunSpecific ()
#19 0x95c33aa8 in CFRunLoopRunInMode ()
#20 0x96f2a2ac in RunCurrentEventLoopInMode ()
#21 0x96f29ffe in ReceiveNextEventCommon ()
#22 0x96f29f39 in BlockUntilNextEventMatchingListInMode ()
#23 0x976b16d5 in _DPSNextEvent ()
#24 0x976b0f88 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#25 0x978ee38d in -[NSApplication _realDoModalLoop:peek:] ()
#26 0x978e8acb in -[NSApplication runModalForWindow:] ()
#27 0x978d9bb6 in -[NSSavePanel(NSSavePanelRuntime) runModalForDirectory:file:types:] ()
#28 0x00004764 in SelectDirectory () at /Users/kinglab/Desktop/C3.3.5/FracController.m:41
#29 0x0000ecb3 in -[MyFooGLView LoadSurfBut:] (self=0x1a7080, _cmd=0x2db85, sender=0x1269c0) at /Users/kinglab/Desktop/C3.3.5/MyFooGLView.m:633
#30 0x97782e8f in -[NSApplication sendAction:to:from:] ()
#31 0x97782dcc in -[NSControl sendAction:to:] ()
#32 0x97782c52 in -[NSCell _sendActionFrom:] ()
#33 0x977822ab in -[NSCell trackMouse:inRect:ofView:untilMouseUp:] ()
#34 0x97781afe in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] ()
#35 0x977813b8 in -[NSControl mouseDown:] ()
#36 0x9777faf7 in -[NSWindow sendEvent:] ()
#37 0x9774c6a5 in -[NSApplication sendEvent:] ()
#38 0x976a9fe7 in -[NSApplication run] ()
#39 0x976771d8 in NSApplicationMain ()
#40 0x00001ffc in main (argc=1, argv=0xbfffe7cc) at /Users/kinglab/Desktop/C3.3.5/main.m:15

Sydde
Sep 30, 2010, 01:54 PM
Change the third line to

NSArray *fileTypes = [[NSArray alloc] initWithObjects:@"asc", nil];

and see if the crashes persist.