是线程 1:信号 SIGABRT 始终是连接问题 (cgimagedestinationfinalize)

is thread 1: signal SIGABRT always a connection issue (cgimagedestinationfinalize)

使用这个块,我的应用程序每次尝试时都会崩溃

CGImageDestinationFinalize(gifDest!)

阻止

func createGIF(with images: [CGImage], data: Data, loopCount: Int, frameDelay: Double) -> Data {
    print("()createGIF.HandHistoryTableVC")
    let gifDest = CGImageDestinationCreateWithData(data as! CFMutableData, kUTTypeGIF, images.count, nil)
    let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
    CGImageDestinationSetProperties(gifDest!, fileProperties as CFDictionary?)
    let frameProperties = [(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): frameDelay]]
    for img in images {
        CGImageDestinationAddImage(gifDest!, img, frameProperties as CFDictionary?)
    }
    print("GIF in Progress")
    CGImageDestinationFinalize(gifDest!)
    print("gifMade")
    return data;
}

错误报告

我迷失了这次崩溃的原因。所有关于 "Thread 1: signal SIGABRT" 的研究似乎都说这是一个连接问题,但如果我注释掉 CGImageDestinationFinalize()

,我的整个应用程序工作正常
func createGIF(with images: [CGImage], data: CFMutableData, loopCount: Int, frameDelay: Double) -> Data {
    print("()createGIF.HandHistoryTableVC")
    let gifDest = CGImageDestinationCreateWithData(data, kUTTypeGIF, images.count, nil)
    let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
    CGImageDestinationSetProperties(gifDest!, fileProperties as CFDictionary?)
    let frameProperties = [(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): frameDelay]]
    for img in images {
        CGImageDestinationAddImage(gifDest!, img, frameProperties as CFDictionary?)
    }
    print("GIF in Progress")
    CGImageDestinationFinalize(gifDest!)
    print("gifMade")
    return data as Data;
}

使用 CFMutableData 初始值设定项

CFDataCreateMutable(kCFAllocatorDefault, 0)

解决了这个问题。