【问题标题】:EXC_BAD_ACCESS KERN_INVALID_ADDRESS ios 11.2 swift 4.0EXC_BAD_ACCESS KERN_INVALID_ADDRESS ios 11.2 swift 4.0
【发布时间】:2018-03-21 03:20:25
【问题描述】:

我仅在 iOS 11.2 中面临以下代码崩溃。我正在使用 swift 4.0。我试图调试几个小时以重现崩溃但未能成功。这是代码

func prepareNewConnection(conn:String) -> RTCPeerConnection {

    let uuid = UIDevice.current.identifierForVendor?.uuidString

    localAudioTrack = peerConnectionFactory.audioTrack(withTrackId: uuid!)

        mediaStream = peerConnectionFactory.mediaStream(withStreamId: LOCAL_MEDIA_STREAM_ID)
        if(localAudioTrack != nil && mediaStream != nil)
        {
            mediaStream.addAudioTrack(localAudioTrack!) //Crash on this line
        }

    let pc = peerConnectionFactory.peerConnection(with: rtcConfig, constraints: mediaConstraints, delegate: self)
    if(mediaStream != nil)
    {
        pc.add(mediaStream)
    }

return pc;
}

这是崩溃分析报告。

我将非常感谢任何帮助。

【问题讨论】:

  • 您为什么不正确安全地解开localAudioTrackmediaStream
  • 你能给我举个例子吗?我不明白“正确安全地展开”是什么意思。我会很感激的。
  • 我正在检查 localAudioTrack 和 mediaStream 的 nil 值。
  • 但是您没有正确执行此操作。另一个线程可以将它们设置为nil。使用if let 安全地打开它们。
  • 你能在答案中写下编辑我的代码以便我接受吗?谢谢。

标签: ios swift ios11.2


【解决方案1】:

请避免安全展开,使用 if let ..

 func prepareNewConnection(conn:String) -> RTCPeerConnection {

   if let uuid = UIDevice.current.identifierForVendor?.uuidString {
localAudioTrack = peerConnectionFactory.audioTrack(withTrackId: uuid) //removed safely Unwrapping
    mediaStream = peerConnectionFactory.mediaStream(withStreamId: LOCAL_MEDIA_STREAM_ID)
 let pc = peerConnectionFactory.peerConnection(with: rtcConfig,constraints: mediaConstraints, delegate: self)
    if(localAudioTrack != nil && mediaStream != nil)
    {
        mediaStream.addAudioTrack(localAudioTrack)
        pc.add(mediaStream) 
    }
  }
 return pc
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 2012-10-09
    • 2017-04-02
    • 2020-04-13
    • 2023-03-23
    • 2015-12-18
    相关资源
    最近更新 更多