Swift:UnsafeMutablePointer.deinitialize在附加到数组时带有负数的致命错误

时间:2016-10-17 07:17:50

标签: ios swift video avassetexportsession

以下代码会生成此错误(附加到exporters):

  

致命错误:UnsafeMutablePointer.deinitialize with negative count

    var exporters = [AVAssetExportSession]()

    let exporter = AVAssetExportSession(asset: mainComposition, presetName: AVAssetExportPresetHighestQuality)!
    exporter.videoComposition = videoComposition
    exporter.outputFileType = AVFileTypeMPEG4
    exporter.outputURL = exportURL
    exporter.shouldOptimizeForNetworkUse = true
    exporters.append(exporter)

StackOverflow上关于UnsafeMutablePointer.deinitialize的其他帖子并没有对这个问题有所了解,这种情况不会持续发生。

有什么想法吗?

1 个答案:

答案 0 :(得分:26)

我遇到了类似的错误,问题是多个线程同时修改数组引起的。在串行调度队列中包装追加调用解决了它。

    let serialQueue = DispatchQueue(label: "myqueue")

    serialQueue.sync {
        exporters.append(exporter)
    }