Crashed when convert CIImage to UIImage

I have written a function that convert CIImage to the UIImage, but 1 out of 100 users is experiencing this crash. I can't replicate it and unable to debug it.


12. Crashed: com.apple.root.default-qos

0 CoreImage 0x1adf5c8b0 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 2388

1 CoreImage 0x1adf5c8b0 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 2388

2 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

3 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

4 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

5 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

6 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

7 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

8 CoreImage 0x1adf5c2d8 CI::Context::recursive_render(CI::TileTask*, CI::Node*, CGRect const&, CI::Node*, bool) + 892

9 CoreImage 0x1adf5cef4 CI::Context::render(CI::ProgramNode*, CGRect const&) + 116

10 CoreImage 0x1adf777a4 CI::create_cgimage(CI::Context*, CI::Image*, CGRect, CGColorSpace*, CI::PixelFormat, bool, unsigned long) + 2392

11 CoreImage 0x1adf15260 -[CIContext(Internal) _createCGImage:fromRect:format:colorSpace:deferred:textureLimit:] + 1020

12 CoreImage 0x1adf13f4c -[CIContext createCGImage:fromRect:] + 196

13 VectorScanner 0x100d98b74 +[AppUtils changeCIImagetoUIImage:] + 560 (AppUtils.m:560)



The function "changeCIImagetoUIImage" is following code:


+ (UIImage *)changeCIImagetoUIImage:(CIImage *)ciimage{

CIContext *context = [AppSharedTool sharedInstance].ciContext;

CGImageRef cgImage = [context createCGImage:ciimage fromRect:ciimage.extent];

UIImage *uiimage = [UIImage imageWithCGImage:cgImage];

CGImageRelease(cgImage);

[context clearCaches];

return uiimage;

}


Also the CIContext is

- (CIContext *)ciContext{

if (!_ciContext) {

_ciContext = [CIContext contextWithOptions:nil];

}

return _ciContext;

}

Replies

What is the actual crash reason aside from the stack trace?

How large is the image you are trying to process?

Did you ever find a solution for this? I have this issue for a long time with exactly the same stack trace and can't get rid of it.

Did anyone find a solution?

Having this issue on iOS 14 and 15 based on insights from Firebase Crashlytics.

The only common point I found between users is that they have low RAM memory... No idea how to avoid this issue.

My application had many CIImage instances; each time they were rendered through CIContext, they left a non-removable cache in it 😡. This behaviour consumes RAM memory and emits these crashes.

I was able to fix the problem using IOSurface to hold the graphics data.