Swift: UnsafeMutablePointer.deinitialize fatal err

2019-03-24 14:34发布

The code below generates this error (appending to exporters):

fatal error: 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)

The other posts on StackOverflow regarding UnsafeMutablePointer.deinitialize do not shed much light on the issue, which doesn't happen consistently.

Any ideas?

1条回答
趁早两清
2楼-- · 2019-03-24 15:30

I had a similar error, the issue was caused by multiple threads modifying the array at the same time. Wrapping the append calls in a serial dispatch queue solved it for me.

    let serialQueue = DispatchQueue(label: "myqueue")

    serialQueue.sync {
        exporters.append(exporter)
    }
查看更多
登录 后发表回答