GPUImage3 icon indicating copy to clipboard operation
GPUImage3 copied to clipboard

Fatal error in Source/PictureInput.swift: Unexpectedly found nil while unwrapping an Optional value

Open mycroftcanner opened this issue 4 years ago • 2 comments

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

mycroftcanner avatar Jul 01 '20 10:07 mycroftcanner

Is the filterWithPipeline holding a weak reference to image?

mycroftcanner avatar Jul 01 '20 11:07 mycroftcanner

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

mycroftcanner avatar Jul 01 '20 11:07 mycroftcanner