I am getting an EXC_BAD_ACCESS error when attempting to add objects to an array. I understand that this could mean I am pointing to something that doesn't exist in memory, or that the objects contain a nil value.
Code:
- (void)fadeInPlayer:(AVAudioPlayer *)player withMaxVolume:(float)maxVolume {
NSLog(@"player: %@", player);
NSLog(@"maxVolume: %f", maxVolume);
NSMutableArray *playerAndVolume = [NSMutableArray arrayWithObjects: player, maxVolume, nil];
if (player.volume <= maxVolume) {
player.volume = player.volume + 0.1;
NSLog(@"%@ Fading In", player);
NSLog(@"Volume %f", player.volume);
[self performSelector:@selector(fadeInPlayer:withMaxVolume:) withObject:playerAndVolume afterDelay:0.5];
//playerAndVolume array used here because performSelector can only accept one argument with a delay and I am using two...
}
}
The strange thing is that when I print the objects I am trying to add to the console (shown as NSLogs above), they return data:
player: <AVAudioPlayer: 0x913f030>
maxVolume: 0.900000
The app crashes immediately after the NSLogs. The rest of the code works fine without the array, but I need to use it to call performselector:withObject:AfterDelay on the method.
So there must be a problem with how I am initialising the array, or maybe the object types, but I can't figure it out.
Any help appreciated.