嘿,我有一个数组,它保存了我的应用程序中的所有.aif文件路径,这是我通过使用mainBundle和资源找到的。
这个数组需要通过两个视图控制器向下传递,才能到达实际使用的位置。问题是,它要么崩溃,要么记录一些完全错误的东西。当我调试时,我在崩溃时得到了一个EXC_BAD_ACCESS注释,但当我正常运行它时,它就崩溃了。
这就是它发挥作用的地方;
- (void)buildDrumTrigger {
defaultSounds = [[NSArray alloc] initWithObjects: @"kick_3", @"aif", @"snare_1", @"aif", @"HiHat_1", @"aif", @"ride_1", @"aif", @"crash_1", @"aif", @"crash_2", @"aif", @"crash_3", @"aif", @"wave_1", @"aif", nil];
self.DrumObject = [[DrumTrigger alloc] initWithSounds:defaultSounds:5:volumeBox];
[defaultSounds release];
NSLog(@"Possible Sounds: %@", DrumObject.possDrumSounds);
}这将返回以fileName.aif结尾的路径的长列表。你明白了吧。
然而..。
// Change the current view to the options window.
- (IBAction)goToOptionsView {
NSLog(@"Loading options menu");
NSLog(@"DrumObject.drumSounds: %@", DrumObject.drumSounds);
NSLog(@"DrumObject.possDrumSounds: %@", DrumObject.possDrumSounds);
optionsViewController.soundBox2 = DrumObject.drumSounds;
optionsViewController.possDrumSounds = DrumObject.possDrumSounds;
[self presentModalViewController:optionsViewController animated:YES];
}这段代码会导致崩溃。如果我注释掉它处理possDrumSounds的部分,它工作得很好。否则它会崩溃,或者以某种方式改变数组,以包含像UIViewControllers这样的随机对象,我不知道它们来自哪里。
感谢大家的帮助,谢谢!
发布于 2010-09-03 07:51:26
您可能会将数组保留在DrumObject中而不保留它,因此它最终会被垃圾所覆盖。
发布于 2010-09-03 07:49:51
您将在buildDrumTrigger中释放defaultSounds,因此当其他方法尝试访问它时,它会指向已释放的数据。
EXC_BAD_ACCESS表明你正在尝试访问你不能访问的内存,通常是因为你已经释放了它。
https://stackoverflow.com/questions/3632095
复制相似问题