Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mycroftcanner opened this issue Jul 1, 2020 · 2 comments

Comments

@mycroftcanner
Copy link

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
Copy link
Author

Is the filterWithPipeline holding a weak reference to image?

@mycroftcanner
Copy link
Author

mycroftcanner commented Jul 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant