正如标题所示,我遇到了臭名昭著的 rederInContext 崩溃问题。我在网上阅读了很多帖子,但似乎都没有给出如何解决这个问题的任何方法,也没有任何对我有用的东西。
让我们从我已经解释过的常见错误开始。我正在使用@autorelease{ code }
,但没有收到任何内存警告问题。我也试过在主线程上执行,也没有奏效。视图的所有层在到达语句时都不是空的。我已经对它们进行了 NSLogged,它们都不为空。我已经尝试了几种不同的代码,并将发布与它们相对应的错误。
尝试#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 的情况下运行代码。还是崩溃了。