UIGraphicsBeginImageContext renderInContext崩溃

时间:2014-02-22 22:47:04

标签: ios objective-c debugging blur uigraphicscontext

正如标题所示,我遇到臭名昭着的rederInContext崩溃问题。我在线阅读了很多帖子,但似乎没有人提出如何解决这个问题以及任何对我有用的事情。

让我们从已经考虑过的常见错误开始。我正在使用@autorelease{ code }而我没有收到任何内存警告问题。我也试过在主线程上执行,也没用。当视图到达语句时,它们的所有层都不为null。我有NSLogged他们,他们都不是null。我尝试了一些不同的代码,并发布了与它们对应的错误。

学尝试#1

-(void){
    @autorelease{
            //UIGraphicsBeginImageContext(self.mapView.bounds);
            UIGraphicsBeginImageContextWithOptions(self.mapView.bounds, NO, 0.0);
            CGContextRef c = UIGraphicsGetCurrentContext();
            CGContextTranslateCTM(c, 0, 0);
            [self.mapView.layer renderInContext:c];  //Crashes HERE :(
            UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
            viewImage = [viewImage applyBlurWithRadius:4.0f tintColor:[UIColor colorWithWhite:0.2 alpha:0.55] saturationDeltaFactor:1.0 maskImage:nil];
            UIGraphicsEndImageContext();
            UIImageView *newView = [[UIImageView alloc] initWithFrame:self.mapView.frame];
            newView.backgroundColor = [UIColor clearColor];
            newView.image = viewImage;
            newView.tag = 10;
            newView.alpha = 0.1;
            [self.mapView addSubview:newView];
            self.mapView.userInteractionEnabled = NO;
            [UIView animateWithDuration:0.15 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ newView.alpha = 1.0;} completion:^(BOOL finished){}];
    }
}
// ** ERROR MESSAGES **
<Error>: CGImageCreate: invalid image width.

<Error>: CGContextSaveGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextClipToRect: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSaveGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSaveGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSetFillColorWithColor: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextAddRect: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextDrawPath: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextRestoreGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSaveGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextGetBaseCTM: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextConcatCTM: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSetBaseCTM: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSaveGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSaveGState: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextClipToRect: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextBeginTransparencyLayerWithRect: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSetFillColorSpace: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextSetStrokeColorSpace: invalid context 0x1e432510. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

*** -[Not A Type retain]: message sent to deallocated instance 0x1e432510

尝试#2 - 调用mainThread

-(void)blurrEffect{
    [self performSelectorOnMainThread:@selector(captureBlur) withObject:nil waitUntilDone:YES];
}
-(void)captureBlur
{
    @autorelease{
            //UIGraphicsBeginImageContext(self.mapView.bounds);
            UIGraphicsBeginImageContextWithOptions(self.mapView.bounds, NO, 0.0);
            CGContextRef c = UIGraphicsGetCurrentContext();
            CGContextTranslateCTM(c, 0, 0);
            [self.mapView.layer renderInContext:c];  //Crashes HERE :(
            UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
            viewImage = [viewImage applyBlurWithRadius:4.0f tintColor:[UIColor colorWithWhite:0.2 alpha:0.55] saturationDeltaFactor:1.0 maskImage:nil];
            UIGraphicsEndImageContext();
            UIImageView *newView = [[UIImageView alloc] initWithFrame:self.mapView.frame];
            newView.backgroundColor = [UIColor clearColor];
            newView.image = viewImage;
            newView.tag = 10;
            newView.alpha = 0.1;
            [self.mapView addSubview:newView];
            self.mapView.userInteractionEnabled = NO;
            [UIView animateWithDuration:0.15 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ newView.alpha = 1.0;} completion:^(BOOL finished){}];
    }
}
// **ERROR MESSAGE**

malloc: *** mmap(size=1923772416) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc

尝试#3

-(void)blurEffect{
   [self performSelector:@selector(captureBlur) withObject:nil afterDelay:0.5];
}
-(void)captureblur{
@autorelease{
            //UIGraphicsBeginImageContext(self.mapView.bounds);
            UIGraphicsBeginImageContextWithOptions(self.mapView.bounds, NO, 0.0);
            CGContextRef c = UIGraphicsGetCurrentContext();
            CGContextTranslateCTM(c, 0, 0);
            [self.mapView.layer renderInContext:c];  //Crashes HERE :(
            UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
            viewImage = [viewImage applyBlurWithRadius:4.0f tintColor:[UIColor colorWithWhite:0.2 alpha:0.55] saturationDeltaFactor:1.0 maskImage:nil];
            UIGraphicsEndImageContext();
            UIImageView *newView = [[UIImageView alloc] initWithFrame:self.mapView.frame];
            newView.backgroundColor = [UIColor clearColor];
            newView.image = viewImage;
            newView.tag = 10;
            newView.alpha = 0.1;
            [self.mapView addSubview:newView];
            self.mapView.userInteractionEnabled = NO;
            [UIView animateWithDuration:0.15 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ newView.alpha = 1.0;} completion:^(BOOL finished){}];
    }
}
// **ERROR MESSAGE**
terminating with uncaught exception of type std::bad_alloc: std::bad_alloc

我也尝试使用已经在stackoverflow上发布的FXBlurView切换自动释放代码。该代码库也使用renderInContext并在同一地点崩溃。

任何人都有任何想法或解决方案,为什么这是打破以及如何解决它?任何指导或信息都有帮助!提前谢谢!

PS:如果我只支持iOS7,我可以使用UIToolbar,但模糊效果看起来很糟糕我正在使用它,我也支持iOS6,所以这是不可能的。

修改:添加了UIGraphicsBeginImageContextWithOptions(self.mapView.bounds.size, NO, 0.0);,并尝试在没有CGContextTranslateCTM的情况下运行代码。仍然坠毁。

0 个答案:

没有答案