简体   繁体   English

ObjectAL:在fadeTo:duration:target:selector上崩溃:

[英]ObjectAL : Crashing on fadeTo:duration:target:selector:

For some reason, which I'm not sure why, my app keeps crashing on the fadeTo method on a OALAudioTrack object. 由于某种原因(我不确定为什么),我的应用程序在OALAudioTrack对象的fadeTo方法上不断崩溃。

I have three different OALAudioTrack objects which are within an array and I only need to change a OALAudioTrack object if a given value is different. 我在数组中有三个不同的OALAudioTrack对象,如果给定值不同,则只需要更改OALAudioTrack对象即可。 When the value is different I need to fade a OALAudioTrack object out and then fade the new OALAudioTrack object in and replace the OALAudioTrack object in the array but I can't do this as it keeps crashing when doing the first fade out (to 0.0f). 当值不同时,我需要淡出一个OALAudioTrack对象,然后淡入一个新的OALAudioTrack对象,并替换数组中的OALAudioTrack对象,但是我不能这样做,因为这样做在第一次淡出时一直崩溃(到0.0f )。 When the app crashes it always crashing on the same line, which is within OALActionManager.m line #159 ( NSUInteger index = [targets indexOfObject:action.target]; ) and the error says "Thread 1 EXE_BAD_ACCESS". 当应用程序崩溃时,它总是崩溃在同一行上,该行在OALActionManager.m第159号行中(NSUInteger index = [targets indexOfObject:action.target];),并且错误显示“线程1 EXE_BAD_ACCESS”。 Is there something I must do before doing the fades, any help would be much appreciated as I've been looking at it for over a day and I can't seem to get past this error. 在执行淡入淡出之前,我必须做些什么吗,由于我已经看了一天多了,所以我将不胜感激,因此我将不胜感激。 The code I am using is below: 我正在使用的代码如下:

if ([[self.soundScapes objectAtIndex:i] isKindOfClass:[OALAudioTrack class]])
{
    [self.tmpSoundScapes removeAllObjects];
    [self.tmpSoundScapes addObject:[fnArr objectAtIndex:i]];
    [self.tmpSoundScapes addObject:[NSNumber numberWithInt:i]];

    OALAudioTrack *currentTrack = [self.soundScapes objectAtIndex:i];

    if ([currentTrack playing])
    {
      NSLog(@"is playing");
      [currentTrack stopFade];

      //This is where the app crashes
      [currentTrack fadeTo:0.0 duration:1.5 target:self selector:@selector(onFadeComplete:)];
    }
}




-(void)onFadeComplete:(id)sender
{
    NSLog(@"fade complete");

    NSString *fn = [self.tmpSoundScapes objectAtIndex:0];
    int i = [[self.tmpSoundScapes objectAtIndex:1] intValue];

    OALAudioTrack *currentTrack = [self.soundScapes objectAtIndex:i];
    [currentTrack stop];
    currentTrack = nil;

    OALAudioTrack* track = [OALAudioTrack track];
    [track preloadFile:fn];
    track.autoPreload = YES;
    track.numberOfLoops = -1;   // Loop forever when playing.            
    track.gain = 0.0f; // volume
    [track play];

    [self.soundScapes replaceObjectAtIndex:i withObject:track];
    [self.soundScapesFiles replaceObjectAtIndex:i withObject:fn];

    int timer;
    if (i==1) 
        timer = 10.0f;
    else if (i==2)
        timer = 25.0f;
    else
        timer = 0.5f;

//    [self performSelector:@selector(onPlayScoundScape:) withObject:[NSNumber numberWithInt:i] afterDelay:timer];
    [track fadeTo:1.0f duration:timer target:self selector:@selector(onPlayScoundScape:)];
}

The part that's crashing is "action.target". 崩溃的部分是“ action.target”。 "target" is a weak reference, so if your track deallocates before the action finishes, it will crash. “目标”是一个弱引用,因此,如果在操作完成之前取消分配轨迹,它将崩溃。

I suspect that at some point your code is either removing the track from self.soundScapes in some other method, or another call to onFadeComplete is being made, generating the same index (thus evicting the currently fading track), before the track fade completes. 我怀疑您的代码有时会以某种其他方法从self.soundScapes中删除该轨道,或者正在进行另一次onFadeComplete调用,从而在轨道淡出完成之前生成相同的索引(从而退出当前正在衰减的轨道)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone中的ObjectAL音频流? - ObjectAL audio streaming in iphone? UIButton没有调用目标的选择器 - UIButton not calling target's selector 核心数据:NSManagedObjectContext保存因无法识别的选择器而崩溃 - Core Data: NSManagedObjectContext save crashing with unrecognized selector 多种方法:按钮的目标和选择器不起作用 - Multiple methods: Target and Selector of button not working iPhone-更改UINavigationController上“后退”按钮的目标或选择器 - iPhone - Change target or selector for Back Button on UINavigationController 将按钮的目标和选择器设置为多个方法 - Set The Target and Selector of a Button to Multiple Methods 应用程序因错误而崩溃:-[NSNull 长度]:无法识别的选择器发送到实例 - App crashing with error: -[NSNull length]: unrecognized selector sent to instance 调试iphone应用程序 - 发送到实例的无法识别的选择器崩溃 - Debugging iphone app - crashing with unrecognized selector sent to instance 搜索NSMutableArray崩溃rangeOfString:options:]:无法识别的选择器已发送到实例 - Searching NSMutableArray Crashing rangeOfString:options:]: unrecognized selector sent to instance 查找UIGestureRecognizer动作(选择器)的名称和目标 - Find UIGestureRecognizer action (selector) name and target
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM