views:

252

answers:

1

Hello all,

I have created a sample application using the iPhone SDK that uses ExtAudioFileOpenURL from the AudioToolBox framework. I have a test.mp3 audio file in my app's document folder. When I tried to open this audio file using this API I received EXEC_BAD_ACCESS. I couldn't figure out why.

Here is a code snippet:

NSArray *arr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *str = [arr objectAtIndex:0];
NSString * temp = [NSString stringWithFormat:@"%@/test.mp3", str];
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)temp, kCFURLPOSIXPathStyle, false);
//AudioFileID fileID ;
//AudioFileOpenURL(url, 0X01, kAudioFileCAFType, &fileID);
ExtAudioFileRef audioFileRef = NULL;
ExtAudioFileOpenURL(url, &audioFileRef);

I get EXC_BAD_ACCESS when I try the ExtAudioFileOpenURL. I thought it was because of the invalid URL passed. But when I tried AudioFileOpenURL it worked fine ensuring me that the URL is valid.

Please help me.

Thanks in advance.

A: 

I wrote this to explain EXC_BAD_ACCESS

http://www.loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html

Basically, you are (probably) either sending messages to dealloced objects or corrupting the heap in some way. When an innocuous call raises EXC_BAD_ACCESS, then it's almost always memory corruption.

You never call release or dealloc in this code, so it's unlikely that this code could cause messages being sent to dealloced objects.

So, probably, whatever is causing EXC_BAD_ACCESS happened before this code. You can prove this by moving this code to very early in your app -- it will probably work. If not, then you do need to really check this code, but if it works, then it's something in between these points.

Probably the most effective way to find the corruption is by enabling Malloc Debug and then following the instructions in my blog to use the debugger to find the line that causes the corrupted heap.

Lou Franco