1

大家好,我有一个数组,其中包含我的应用程序中的所有 .aif 文件路径,这是我通过使用 mainBundle 和资源找到的。

该数组需要通过 2 个视图控制器向下传递才能到达实际使用的位置。问题是,它要么崩溃,要么记录完全错误的东西。当我调试时,我在崩溃时得到一个 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 这样的随机对象,我不知道它们来自哪里。

感谢所有帮助,谢谢!

4

2 回答 2

2

您正在释放defaultSoundsbuildDrumTrigger因此当其他方法尝试访问它时,它指向已被释放的数据。

EXC_BAD_ACCESS 表示您正在尝试访问您无法访问的内存,通常是因为您已经释放了它。

于 2010-09-02T23:49:50.503 回答
2

您可能会在 DrumObject 内部保留数组而不保留它,因此它最终会被垃圾覆盖。

于 2010-09-02T23:51:26.490 回答