Crash When Run app On Xcode15 Simulator

When UICollectionViewFlowLayoutAlertForInvalidItemSize Occured Some Log Like These Occurred, and then app crash

*** Assertion failure in void _UIGraphicsBeginImageContextWithOptions(CGSize, BOOL, CGFloat, BOOL)(), UIGraphics.m:410

crash Output

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 16}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.'

I had the same issue in my project when running the app on iOS 17 Device/Simulator. Reason is "UIGraphicsBeginImageContext" is depreciated with Xcode 15.0 and Later versions.

So, I was find the all "UIGraphicsBeginImageContext" in my App and framework and COMMENTED. After that, Clean all builds (App and FW) and regenerate both. Finally, reinstall. Hopefully this will fix the issue. It's works for me.

We migrated all UIGraphicsBeginImageContext code in all our apps to UIGraphicsImageRenderer and the crashes disappeared. Now everything is good again.

    UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat defaultFormat];
    format.opaque = NO;
    format.scale = 1;
    format.preferredRange = UIGraphicsImageRendererFormatRangeStandard; 

    UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:imageSize format:format];

    UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) 
    {
        CGContextRef context = rendererContext.CGContext;

        
    }];

We are aslo facing same issue on xcode 15

Update react-native-linear-gradient to version 2.8.3.

this problem may also be related to the react-native version. I am using react native version 0.68.1 and in this version UIGraphicsBeginImageContext() methods are used. new react native versions do not use these methods.

If your project is small, you can switch to the new react native version.

You can check this video as a solution: https://www.youtube.com/watch?v=psIBtbwMLQE

The fact is that if you build the project with XCode15 and run the app on iOS17, it will crash. But if you build the project with XCode14 or earlier version, it will not crash on iOS17. I don't understand how the difference is caused since UIKit is a system dynamic library, it is built-in in the iphone's iOS17. If anyone can explain the cause of the difference, I'm all your ears.

Crash When Run app On Xcode15 Simulator
 
 
Q