Chase S
Chase S

Reputation: 468

BSXPCMessage Error on CIContext & Performance in iOS8

I get this error BSXPCMessage received error for message: Connection interrupted showing up whenever I create a CIContext for an image I am going to allow the user to edit. This error can be found on other stackoverflow question like this one - BSXPCMessage received error for message: Connection interrupted on CIContext with iOS 8

However, while the accepted answer (https://stackoverflow.com/a/26268910/2939977) does work in eliminating the error message it spikes the CPU usage to unusable level and makes the UI get very choppy (CPU usage from 50% to about 150% once the kCIContextUseSoftwareRenderer flag is set to YES) as my filters are attached to sliders and performance is paramount.

I tried following apple documentation here to create an EAGL context to create my CIContext that I set the color space to null.

EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
imageContext = [CIContext contextWithEAGLContext:myEAGLContext options:options];

This creates the filter without the error message and performance is much much better Hooray! However, as soon as the user engages the editing options to adjust the image I get the BSXPCMessage received error for message: Connection interrupted on the first adjustment. I never see the error message again and it does not seem to effect the output at all.

[filter setValue:@(contrast) forKey:@"inputContrast"];
[filter setValue:@(color) forKey:@"inputSaturation"];

CIImage *outputImage = [filter outputImage];
CGImageRef cgimg = [imageContext createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImage = [UIImage imageWithCGImage:cgimg scale:1 orientation:UIImageOrientationRight];
transitionImage.image = newImage;
CGImageRelease(cgimg);

In case you are wondering I did start on GPUImage because of the better performance when using filters on sliders but found it had some other issues when it came to image scaling that cause me to remove it and go down the CIFilter route.

Any advice or help would be greatly appreciated :)

Upvotes: 0

Views: 1461

Answers (1)

David Hayward
David Hayward

Reputation: 565

If you are going to create a CIContext with:

[CIContext contextWithEAGLContext:options:] 

then you should draw directly into that context using:

[cictx drawImage:inRect:fromRect:]

This will be much faster than creating a CGImageRef and passing that to a UIImageView.

Upvotes: 0

Related Questions