gpt4 book ai didi

ios - CIContext 错误访问崩溃

转载 作者:可可西里 更新时间:2023-11-01 05:28:33 24 4
gpt4 key购买 nike

我已经编写了一个函数来模糊图像,但每 100 个用户中就有 1 个遇到这种崩溃。我无法复制它,也无法调试它。

这是崩溃日志:

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

以下是我的模糊函数:

- (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;
}

最佳答案

尝试在实例化 CIContext 之前将 EAGLContext 的当前上下文设置为 nil>

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

关于ios - CIContext 错误访问崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27632618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com