The code below generates this error (appending to exporters
):
fatal error: UnsafeMutablePointer.deinitialize with negative count
I have solved this type of issue like this way:
DispatchQueue.global(qos: .background).sync {
//your code
}
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)
}