CIContext access error

I wrote a function to blur an image, but 1 in 100 users experienced this crash. I cannot replicate it and cannot debug it.

This is the crash log:

Thread : Crashed: com.apple.root.background-qos

0  libGPUSupportMercury.dylib     0x296fb8fe gpus_ReturnNotPermittedKillClient 
1  libGPUSupportMercury.dylib     0x296fc3cb gpusSubmitDataBuffers 
2  libGPUSupportMercury.dylib     0x296fc249 gldCreateContext 
3  GLEngine                       0x252ff93b gliCreateContextWithShared 
4  OpenGLES                      0x253dbab3 -[EAGLContext initWithAPI:properties:] + 406 
5  CoreImage   0x2303ba8b ___ZN2CI11can_use_gpuEv_block_invoke + 142 
6  libdispatch.dylib              0x307107a7 _dispatch_client_callout + 22 
7  libdispatch.dylib              0x307113eb dispatch_once_f + 62 
8 CoreImage                      0x2303b9fb CI::can_use_gpu() + 98 
9  CoreImage                      0x22fb9b79 +[CIContext contextWithOptions:] + 188 
10 Test                         0x0016121b
    -[NewRestaurantViewController blur:]  
12 libdispatch.dylib              0x307107bb _dispatch_call_block_and_release + 10 
13 libdispatch.dylib  0x30719dab _dispatch_root_queue_drain + 866 
14 libdispatch.dylib       0x3071acd7 _dispatch_worker_thread3 + 94 
15 libsystem_pthread.dylib    0x30871e31 _pthread_wqthread + 668

      

Below is my blur function:

- (UIImage *)blur:(UIImage*)theImage{
    if(theImage == nil){
        return theImage;
    }
    // create our blurred image

    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];

    // setting up Gaussian Blur (we could use one of many filters offered by Core Image)
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setDefaults];
    [filter setValue:inputImage forKey:@"inputImage"];
    [filter setValue:[NSNumber numberWithFloat:10.0f] forKey:@"inputRadius"];
    CIImage *result = [filter valueForKey:@"outputImage"];

    // CIGaussianBlur has a tendency to shrink the image a little,
    // this ensures it matches up exactly to the bounds of our original image

    CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];

    UIImage *returnImage = [UIImage imageWithCGImage:cgImage];//create a UIImage for this function to "return" so that ARC can manage the memory of the blur... ARC can't manage CGImageRefs so we need to release it before this function "returns" and ends.
    CGImageRelease(cgImage);//release CGImageRef because ARC doesn't manage this on its own.

    return returnImage;   
}

      

+3


source to share


1 answer


Try to set the EAGLContext

current context to zero before creatingCIContext



[EAGLContext setCurrentContext:nil];
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];

      

+4


source







All Articles