Swift: UnsafeMutablePointer.deinitialize fatal error with negative count when appending to array

前端 未结 2 1178
花落未央
花落未央 2021-02-05 04:56

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

fatal error: UnsafeMutablePointer.deinitialize with negative count

2条回答
  •  被撕碎了的回忆
    2021-02-05 05:36

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

提交回复
热议问题