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 have the same issue, but on a real device. Not using the simulator. Did you find a solution?

I'm seeing it on both device and simulator. Somehow it sometimes doesn't happen on a sim.

This is still an issue with Xcode 15 beta 5/iOS 17 beta 4

The crash is caused by calling UIGraphicsBeginImageContextWithOptions() with a size where either the width or height is 0. e.g. (0,0). The tricky part is that it somehow crashes completely and doesn't give you a full stack trace so you can track down the source of the problem.

I have the same issue, but on a real device. Not using the simulator. Did you find a solution?

In our case, we found the issue was caused by a resizable image in a UIImageView that was set to tile mode for resizing the center. Luckily for the image being used we could switch to stretch and get the same result, and the exception has gone away. Your results may vary.

Did you guys found any fix for this??

any updates on this issue?? it would be very helpful

Exception thrown while executing UI block: UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.

__44-[RCTUIManager flushUIBlocksWithCompletion:]_block_invoke RCTUIManager.m:1202 __44-[RCTUIManager flushUIBlocksWithCompletion:]_block_invoke.206 __RCTExecuteOnMainQueue_block_invoke

this is the error In React native

I have the same issue now, does anyone have any solution?

Same issue. No solutions?

Same error here, Exception thrown while executing UI block: UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.

any solutions?

Solution is make sure the size is not zero. In my case, I changed the view init from MyView() to MyView(frame: self.view.bounds), and then the crash is gone.

UIGraphicsBeginImageContextWithOptions is deprecated use UIGraphicsImageRenderer, this occurs on ios >= 17 both simulator and phones

I have the same exact issue in react-native app. Is there a solution for this? Using xCode v15 and trying to run the app on iPhone 15 simulator

Here is an SO, can probably help migrate to the new UIGraphicsImageRenderer usage. https://stackoverflow.com/a/40867644/1154836

I've run into this error as well. Has anyone figured out a workaround? Should I just download xcode 14? Or is the issue with Ios 17? I currently am using React Native, so I don't think I have control over the UIGraphicsBeginImageContext() stuff.

I've checked my ui elements and I don't think anything is set to Width: 0 or Height: 0.

I had the same issue in my react-native project when running the app on iOS 17 simulator. After banging my head for 2 days I finally fixed this issue.

Reason The reason for this error is that the UIGraphicsBeginImageContext and UIGraphicsBeginImageContextWithOption are depreciated.

Fix To fix this issue either remove, comment or replace UIGraphicsBeginImageContext and UIGraphicsBeginImageContextWithOption with UIGraphicsImageRenderer. To do this here are the steps that I followed.

  1. First search the whole project with the command grep -r "UIGraphicsBeginImageContext" ./ this will list all the files using UIGraphicsBeginImageContext or UIGraphicsBeginImageContextWithOption. This step is important as you won't know how many packages are there which refrences the UIGraphicsBeginImageContext. In my case I had several react-native packages as well as pods having UIGraphicsBeginImageContext

  2. Then one-by-one remove or replace it with UIGraphicsImageRenderer. Replacing with UIGraphicsImageRenderer will be tricky if you don't have good idea of objective c. So, I suuggest first commenting and then checking if hte solution works for you.

  3. Clean project, delete the app from simulator and then reinstall. Hopefully this will fix the issue. It did for me.

For expediency (and backward compatibility), you could find all occurrences of UIGraphicsBeginImageContext in your code, and add a size check just beforehand, returning early with a nil image if the size is invalid. For example:

    if (size.width <= 0 || size.height <= 0) { return nil; }
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);

It occurs when running a simulator with iOS 17. Down stepping the simulator to pre iOS 17 isn't much use if you want to release to production.

For me, using React Native, patching source is not a nice option. However, as suggested elsewhere, I was able to search for UIGraphicsBeginImageContext in the code and discover that several libraries were needing updated, react-native-svg, react-native-linear-gradient, react-native-vector-icons and I had to replace the deprecated react-native-camera.

On react native it turns out to be FastImage package issue, refer to https://github.com/DylanVann/react-native-fast-image/issues/1002

From my side I was facing due to incompatibility of Pod (Dynatrace). I just used pod from dynatrace document and issue got fixed for me. Previously pod was used from any other website.

use UIGraphicsImageRenderer instead of UIGraphicsBeginImageContext, I faced same crash and i fixed that.

We are also seeing crashes with UIGraphicsBeginImageContext on iOS 17 devices. At first we also thought that it would happen because of a 0 in the width or height of the size. But it crashes in one app at this point:

    if(size.width < 50 || size.height < 50)
    {
        return nil;
    }
    
    size = CGSizeMake(size.width*2.0f, size.height*2.0f);
    
    UIGraphicsBeginImageContext(size);

With this code, it is impossible for the width or height to be 0. The crash must therefore also have other causes. Unfortunately, we cannot reproduce the crash with our test devices.

Incident Identifier: AAAAAAAAAA-893D-4C7B-A933-AAAAAAAAAA
Hardware Model:      iPad13,16
Process:             AAAAAAAAAA [37228]
Path:                /private/var/containers/Bundle/Application/AAAAAAAAAA-F8FB-405B-8DC7-AAAAAAAAAA/AAAAAAAAAA.app/AAAAAAAAAA
Identifier:          AAAAAAAAAA.AAAAAAAAAA.AAAAAAAAAA
Version:             13.6 (1.0)
AppStoreTools:       15A240a
AppVariant:          1:iPad13,16:15
Code Type:           ARM-64 (Native)
Role:                Background
Parent Process:      launchd [1]
Coalition:           AAAAAAAAAA.AAAAAAAAAA.AAAAAAAAAA [700]

Date/Time:           2023-11-24 21:03:57.5000 -0500
Launch Time:         2023-11-24 08:47:34.0066 -0500
OS Version:          iPhone OS 17.1.1 (21B91)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: SIGNAL 6 Abort trap: 6
Terminating Process: AAAAAAAAAA [37228]

Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                	0x18863c870 __exceptionPreprocess + 164 (NSException.m:249)
1   libobjc.A.dylib               	0x1809a7c00 objc_exception_throw + 60 (objc-exception.mm:356)
2   Foundation                    	0x187ba6e54 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 172 (NSException.m:261)
3   UIKitCore                     	0x18a8683a4 _UIGraphicsBeginImageContextWithOptions + 568 (UIGraphics.m:407)
4   AAAAAAAAAA                    	0x100a9e83c -[AAAAAAAAAA getAaaaaImage:] + 88 (AAAAAAAAAA.m:7815)
5   AAAAAAAAAA                    	0x100a9e6b0 -[AAAAAAAAAA createAaaaa] + 92 (AAAAAAAAAA.m:7783)
6   AAAAAAAAAA                    	0x100a8b14c -[AAAAAAAAAA setAaaaaSize:] + 2664 (AAAAAAAAAA.m:2566)
7   AAAAAAAAAA                    	0x100a84164 -[AAAAAAAAAA viewDidLayoutSubviews] + 284 (AAAAAAAAAA.m:890)
8   UIKitCore                     	0x18a7a67f0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1876 (UIView.m:20001)
9   QuartzCore                    	0x189bbc1c0 CA::Layer::layout_if_needed(CA::Transaction*) + 500 (CALayer.mm:10804)
10  UIKitCore                     	0x18a7a9744 -[UIView(Hierarchy) layoutBelowIfNeeded] + 296 (UIView.m:14119)
11  UIKitCore                     	0x18a7ac3e8 -[UINavigationController _layoutViewController:] + 816 (UINavigationController.m:7728)
12  UIKitCore                     	0x18a7ac0b4 -[UINavigationController _layoutTopViewControllerLookForNested:] + 436 (UINavigationController.m:5626)
13  UIKitCore                     	0x18a9392a0 __105-[UINavigationController _repositionPaletteWithNavigationBarHidden:duration:shouldUpdateNavigationItems:]_block_invoke + 440 (UINavigationController.m:3149)

If you use React-Native and dependency react-native-fast-image, follow this issue. i solved the same problem with this help.

https://github.com/DylanVann/react-native-fast-image/issues/1002

Do you still observe this problem? In crashlytics, I only see this problem with iOS 17.0.x versions. I think since iOS 17.1 this problem is fixed.

Crash When Run app On Xcode15 Simulator
 
 
Q