Swift:UnsafeMutablePointer.deinitialize在附加到数组时带有负数的致命错误 [英] Swift: UnsafeMutablePointer.deinitialize fatal error with negative count when appending to array

查看:1280
本文介绍了Swift:UnsafeMutablePointer.deinitialize在附加到数组时带有负数的致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码会产生此错误(附加到导出器):

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


致命错误:UnsafeMutablePointer.deinitialize with negative count

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)

StackOverflow上关于 UnsafeMutablePointer.deinitialize 的其他帖子不会流失这个问题很少发生,这不会持续发生。

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

任何想法?

推荐答案

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

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)
    }

这篇关于Swift:UnsafeMutablePointer.deinitialize在附加到数组时带有负数的致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆