Search code examples
iosobjective-cxcodedebuggingbreakpoints

Xcode Exception Breakpoint Always Pauses On Property


This has driven me nuts for a long time now. I am using Xcode 4.6 but this has been happening for several versions. When I turn on breakpoints and add the Exception Breakpoint, it always pauses on a line of code where I'm setting up an audio player. I set some up before and after the same way, but it only pauses on that one.

Here is the code I'm using:

    [[AVAudioSession sharedInstance] setDelegate: self];
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];

    NSError *activationError = nil;
    [[AVAudioSession sharedInstance] setActive: YES error: &activationError];

    self.playedSongs = [NSMutableSet setWithCapacity:9];
    [self loadSettingsFromFile];
    NSURL *sfxPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Snap.aiff" ofType:nil]];
    self.snapSfx = [[[AVAudioPlayer alloc]initWithContentsOfURL:sfxPath error:nil]autorelease];
    self.snapSfx.volume = 1.f;

    NSURL *fireworksPath;
    if ([OriginalIPadChecker isNotiPadOriginal]) {
        fireworksPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"FireworksSFX.mp3" ofType:nil]];
   }
    else{
        fireworksPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"NoFireworksSFX.mp3" ofType:nil]];
    }
    self.fireWorksSfx = [[[AVAudioPlayer alloc]initWithContentsOfURL:fireworksPath error:nil]autorelease];
    self.fireWorksSfx.volume = 1.f;

    NSURL *poofPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Remove Poof.mp3" ofType:nil]];

    //The line below is the one that it pauses on
    self.removePoof = [[[AVAudioPlayer alloc]initWithContentsOfURL:poofPath error:nil]autorelease];
    self.removePoof.volume = 1.f;

    NSURL *newHighScorePath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"New High Score.mp3" ofType:nil]];
    self.theNewHighScore = [[[AVAudioPlayer alloc]initWithContentsOfURL:newHighScorePath error:nil]autorelease];
    self.theNewHighScore.volume = 1.f;

    NSURL *badgeInTrophyPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Badge In Trophy.aiff" ofType:nil]];
    self.badgeInTrophy = [[[AVAudioPlayer alloc]initWithContentsOfURL:badgeInTrophyPath error:nil]autorelease];
    self.badgeInTrophy.volume = 1.f;

    NSURL *dingPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Ding.aif" ofType:nil]];
    self.ding = [[[AVAudioPlayer alloc]initWithContentsOfURL:dingPath error:nil]autorelease];
    self.ding.volume = 1.f;

The app doesn't crash and the sound plays fine, but the debugger always pauses on that one line—even if I move it somewhere else, it still pauses. I can continue the execution and it works just fine, but this really bugs me.

I don't get why it pauses. Any ideas?


Solution

  • Try this and update the question on where it stops (if it stops):

    AVAudioPlayer *foo;
    NSError *error = nil;
    assert(poofPath);
    
    foo = [AVAudioPlayer alloc];
    foo = [foo initWithContentsOfURL:poofPath error:&error];
    assert(foo);
    [self setRemovePoof:foo];
    [foo release];
    

    If the assert kicks in, that's probably an Apple issue. Unfortunately there are cases of Apple internal frameworks using try/catch, and they will trigger the breakpoint. Its not common but does happen.

    If in the end that foo is not nil and the error is also nil, the best you can do is enter a bug report at bugreporter.apple.com (which would be great). Also, did you look at poofPath - is there any chance that the URL returns anything other than pristine audio?

    My guess is that Apple tries to open and process the file, its gets an internal exception because there is something "odd" or abnormal about the file. Then the framework does additional work, and manages to read the file. So you get your sound but the exception too. Take some common type of mp3 and put that in your app bundle, and try to open it. See if it (and maybe a few other files) gives the same error. Or create a demo project with the sound and upload it (in the end you may need to submit the demo project to Apple in a bug report). These kinds of things should be bug reported.

    EDIT: Unfortunately there are cases of Apple internal frameworks using try/catch, and they will trigger the breakpoint. Then, as mentioned earlier, some later code finally figures out how to decode the file and does.

    The original poster has responded in a comment that this particular file was created with Audacity, and has heard that such files often have decode issues.