UIImage imageWithSize (UIGraphicsBeginImageContext) causing crash on iOS 17 (XCode 15)
What happened?
On the latest version of react-native-navigation and react-native, when we are trying to run our app on iOS 17, we are receiving the following main thread crash:
Exception NSException * "UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={1, 0}, scale=1.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert." 0x0000600000d35170
It seems to be cause by UIGraphicsBeginImageContext(size); inside the imageWithSize method in UIImage+utils.m
When commenting out the line it works. I assume it's because it's passing the height as 0, but not sure where this is coming from as the stack-trace is incomplete. This should definitely be handled.
Potentially some more useful information here: https://developer.apple.com/forums/thread/733326
What was the expected behaviour?
No response
Was it tested on latest react-native-navigation?
- [X] I have tested this issue on the latest react-native-navigation release and it still reproduces.
Help us reproduce this issue!
No response
In what environment did this happen?
React Native Navigation version: 7.37.0-hotfix.1 React Native version: 0.72.5 Has Fabric (React Native's new rendering system) enabled: no Device model: iPhone 15 Pro iOS version: 17.0
It seems to happen when we set
bottomTabs: {
backgroundColor: globalStyles.colors.base,
borderColor: globalStyles.colors.gray2,
borderWidth: Platform.OS === 'ios' ? 0 : 1,
},
Setting it to 0 or to null both causes the crash... - setting it to undefined fixed it.
Would still be good to handle the 0 case.
@OskarEichler you are a live saver! And indeed, it should accept 0 or even null
Anyone able to solve this? Setting the options did not solve it for me.
Edit: Solved by setting the following:
Navigation.setDefaultOptions({
bottomTabs: {
borderWidth: undefined,
}
})
Before i had Platform.OS === 'ios' ? 0 : 1 for theborderWidth. Should support null or 0
in my case it happened when tintColor was passed in FastImage
<FastImage tintColor={'#000000'} style={styles.iconStyle1} source={require('../../assets/close.png')} />
this fixed the issue
<Image style={[styles.iconStyle1, { tintColor: '#000000' }]} source={require('../../assets/close.png')} />