Why does CIContext.init() returns nil when it should not?

Viewed 47

I'm really confused by the fact that I have a situation where CIContext constructor returns nil when it should not according to the API definitions.

I have this code:

if (context == nil) {
    print("creating default context")
    context = CIContext()
    print("default context is nil: ", context == nil)
}

if (context == nil) {
    print("creating context 1 with options")
    context = CIContext(options: [.allowLowPower: true])
    print("context is nil: ", context == nil)
}

if (context == nil) {
    print("creating context 2 with options")
    context = CIContext(options: [.useSoftwareRenderer: true])
    print("context is nil: ", context == nil)
}

It gives me this output:

creating default context
default context is nil:  true

creating context 1 with options
context is nil:  true

creating context 2 with options
context is nil:  false

i.e. the first two blocks initialize context to nil. How can that be when API says it should not be nil?

BTW: this is happening just on CI machines, which are 7year old Mac Pros probably with no monitor connected to it.

0 Answers
Related