Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CIContext bad access crash

I have written a function to blur the image, but 1 out of 100 users is experiencing this crash. I cant replicate it and unable to 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

Following 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;   
}
like image 992
nikunj492 Avatar asked Mar 17 '23 12:03

nikunj492


1 Answers

Try setting EAGLContext's current context to nil before instantiating CIContext

[EAGLContext setCurrentContext:nil];
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];
like image 171
TGygi Avatar answered Mar 29 '23 08:03

TGygi