AudioKit crash: required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode

梦想与她 提交于 2020-01-11 09:06:13

问题


We are experiencing an exception in our project:

2019-08-08 10:18:28.703708-0600 AppName[99385:5069475] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ee2e8db __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010e21bac5 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ee2e662 +[NSException raise:format:arguments:] + 98
    3   AVFAudio                            0x0000000111b94dbc _Z19AVAE_RaiseExceptionP8NSStringz + 156
    4   AVFAudio                            0x0000000111bf3937 _Z11_AVAE_CheckPKciS0_S0_b + 295
    5   AVFAudio                            0x0000000111b8cb8f _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 1031
    6   AVFAudio                            0x0000000111bfb598 _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 194
    7   AVFAudio                            0x0000000111bfb5ff -[AVAudioEngine connect:to:format:] + 83
    8   AppName                             0x000000010a424c10 $s8AudioKitAAC6outputAA6AKNodeCSgvWZTf4dd_n + 2576
    9   AppName                             0x000000010a4230fd $s8AudioKitAAC6outputAA6AKNodeCSgvsZ + 93
    10  AppName                             0x000000010a2ba3a3 $s6AppName7MaestroC17setUpTrackPlayers7fileURLy10Foundation0H0V_tF + 1235

Examining the common gotchas video I see a similar exception being thrown, required condition is false: !nodeMixerConns.empty() && !hasDirectConnToIONode, which is caused by allowing the variables to go out of scope rather than be retained in the class.

So this occurs when we create an AKPlayer, which is retained in a class, then we create an AKTimePitch with this player which is also retained in that class, and finally assign that to AudioKit.output which triggers the exception. After that we were storing the class that holds onto the player and time pitch in an array, so I tried to move this up after it's created in hopes that was the issue, but I see the same exception.

Interestingly, this code works fine initially when we load up the first song but crashes when we hit the next button to load up the next song.

final class Maestro : NSObject {
    static let shared = Maestro()

    var audioPlayers = [TrackPlayer]()

    func setUpTrackPlayers(fileURL: URL) {
        let playerOne = TrackPlayer(url: fileURL)
        audioPlayers.append(playerOne)

        AudioKit.output = playerOne.handleMixerChain() //boom

        do {
            try AudioKit.start()
        } catch {
            print("Maestro AudioKit.start error: \(error)")
        }
    }

    func next() {
        for player in audioPlayers {
            player.stop()
        }
        audioPlayers.removeAll()

        setUpTrackPlayers(fileURL: newSong.getFileUrl())
    }
}

final class TrackPlayer {
    let player : AKPlayer
    lazy var timePitch = AKTimePitch()

    init(url: URL) {
        player = AKPlayer(url: url)!
    }

    func handleMixerChain(pitch: Double = 0.0, tempo: Double = 1.0) -> AKTimePitch {
        timePitch = AKTimePitch(player)
        timePitch.pitch = pitch
        timePitch.rate = tempo
        return timePitch
    }
}

Any ideas? If you need any more info let me know. May be good to note we are updating from AudioKit 4.5.5 where we didn't experience this crash.


回答1:


I've opened the project and it seems like you're being a bit too relaxed about your set up / tear down of the signal chain. You're setting up AudioKit's output using local variables, never tearing down this signal chain, and then coming back resetting the AudioKit output and telling AudioKit to start without ever calling AudioKit.stop().



来源:https://stackoverflow.com/questions/57417554/audiokit-crash-required-condition-is-false-destnodemixerconns-empty-isd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!