GPUImage3
GPUImage3 copied to clipboard
Fatal error in Source/PictureInput.swift: Unexpectedly found nil while unwrapping an Optional value
Trying to use GPUImage3 inside a ASNetworkImageNode's imageModificationBlock:
node.imageModificationBlock = { image, _ in
let luminance = Luminance()
let exposure = ExposureAdjustment()
exposure.exposure = -0.3
return image.filterWithPipeline { input, output in
input --> luminance --> exposure --> output
}
}
It crashes sometimes with the following error:
Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /Users/mc/Test/GPUImage3/framework/Source/PictureInput.swift, line 20
#if canImport(UIKit)
public convenience init(image:UIImage, smoothlyScaleOutput:Bool = false, orientation:ImageOrientation = .portrait) {
self.init(image: image.cgImage!, smoothlyScaleOutput: smoothlyScaleOutput, orientation: orientation)
}
Is the filterWithPipeline holding a weak reference to image?
The solution is to make sure image.cgImage isn't nil :
node.imageModificationBlock = { image, _ in
guard image.cgImage != nil else { return image }
let luminance = Luminance()
let exposure = ExposureAdjustment()
exposure.exposure = -0.3
return image.filterWithPipeline { input, output in
input --> luminance --> exposure --> output
}
}