objcio / functional-swift

Issue repository for the Functional Swift book
http://www.objc.io/books/fpinswift
927 stars 133 forks source link

error while calling colorGenerator #131

Closed qwind365 closed 5 years ago

qwind365 commented 7 years ago
func colorGenerator(color:UIColor) -> Filter {
    return {
        image in

        let params = [kCIInputColorKey:CIColor.init(red: 1, green: 0, blue: 0, alpha: 0.2)] as [String:Any]
        guard let filter = CIFilter.init(name: "CIConstantColorGenerator", withInputParameters: params) else {
            fatalError()
        }

        guard let outputImage = filter.outputImage else     {
            fatalError()
        }
        return outputImage.cropping(to: image.extent)
    }
}

who can tell me how to fix it? thank you !

chriseidhof commented 7 years ago

Hm, on which platform are you trying? What is the error you're getting?

qwind365 commented 7 years ago

@chriseidhof I run it on xcode 8.3.2 playground.

error: Playground execution aborted: error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

JiaLiangoooo commented 7 years ago

I have the same problem

chriseidhof commented 7 years ago

Is this an iOS or Mac playground? Switching between the two might help! Or could you post the complete playground?

high5Fly commented 6 years ago

For me the problem came from how I pass the color.

I used first UIColor - color.ciColor, with this was crashing. Then I switch to this from a comment here "[kCIInputColorKey: CIColor(cgColor: color.cgColor)]" and it worked.

I am on XCode 9.2