0

I'm going to filter the image using CGImageRef.The scenario is while i applied the "CIPhotoEffectChrome" and navigate to back screen, My app is going to crash...And the log displayed EXC_BAD_ACCESS.

HERE is the code:::

- (UIImage *)CIPhotoEffectChrome {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

        dispatch_async(dispatch_get_main_queue(), ^(void){
        });
    });

    CIContext *context = [CIContext contextWithOptions:nil];               // 1

    CIImage *image = [CIImage imageWithCGImage:self.CGImage];               // 2


    CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectChrome"];           // 3

    [filter setValue:image forKey:kCIInputImageKey];

    CIImage *result = [filter valueForKey:kCIOutputImageKey];              // 4

    CGRect extent = [result extent];

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

    UIImage *filterImage=[UIImage imageWithCGImage:cgImage];

    CGImageRelease(cgImage);

    return filterImage;
}

Please help me!!!!!

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Sonu
  • 937
  • 1
  • 10
  • 39

1 Answers1

1

you need to remove CGImageRelease(cgImage) and again run because we dont create it explicitly.

As in your case crash occur when moving back from current view-controller so it means you are fetching images through lazy loading or some other web service so you should set delegate to nil or if the delegate object is declared either strong or retain that should be weak .

Shobhakar Tiwari
  • 7,862
  • 4
  • 36
  • 71