Crashes on iOS
Description
I've noticed 2 crashes in our app related to this library. I'm pasting the crash reports from Bugsnag.
Crash 1
Possible cause
App is backgrounded then possibly change orientation? I only saw this issue on iOS 16.5.1 so it might be related to this certain iOS version?
Crashlog
CrashReporter Key: 881766c857fa167c50e024bcce7ac3e2baad338a
Hardware Model: iPhone12,3
Process: xxx
Identifier: xxx
Version: xxx
Role: Background
OS Version: iOS 16.5.1
NSRangeException: *** -[__NSArrayI_Transfer objectAtIndexedSubscript:]: index 0 beyond bounds for empty array
0 CoreFoundation +0x9cb0 ___exceptionPreprocess
1 libobjc.A.dylib +0x183cc _objc_exception_throw
2 CoreFoundation +0x1aff80 __CFThrowFormattedException
3 CoreFoundation +0xb8228 -[__NSArrayI_Transfer objectAtIndexedSubscript:]
4 xxx +0x8fe430 __56+[RNSScreenWindowTraits enforceDesiredDeviceOrientation]_block_invoke (RNSScreenWindowTraits.mm:181:49)
5 libdispatch.dylib +0x231c __dispatch_call_block_and_release
6 libdispatch.dylib +0x3ea8 __dispatch_client_callout
7 libdispatch.dylib +0x126a0 __dispatch_main_queue_drain
8 libdispatch.dylib +0x122f0 __dispatch_main_queue_callback_4CF
9 CoreFoundation +0x98c24 ___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
10 CoreFoundation +0x7a55c ___CFRunLoopRun
11 CoreFoundation +0x7f3e8 _CFRunLoopRunSpecific
12 GraphicsServices +0x1358 _GSEventRunModal
13 UIKitCore +0x39d6e4 -[UIApplication _run]
14 UIKitCore +0x39d348 _UIApplicationMain
15 xxx +0x70bc main (main.m:8:12)
16 dyld +0x15de8 start
Crash 2
Possible cause
This function seems to be running into an infinite loop. We're displaying a modal screen prior to this crash so I assume that might be the cause. Found this existing bug report too: https://github.com/software-mansion/react-native-screens/issues/1678
Crashlog
CrashReporter Key: fe9b4fb12f3ff773d82d43bdeb56fed61c6a0972
Hardware Model: iPhone14,2
Process: xxx
Identifier: xxx
Version: xxx
Role: Foreground
OS Version: iOS 16.5.1
Exception Type: EXC_BAD_ACCESS
Exception Subtype: KERN_INVALID_ADDRESS
EXC_BAD_ACCESS: Stack overflow in (null)
0 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
1 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
2 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
3 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
4 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
5 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
6 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
7 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
8 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
9 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
10 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
11 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
12 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
13 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
14 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
15 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
16 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
17 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
18 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
19 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
20 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
21 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
22 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
23 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
24 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
25 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
26 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
27 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
28 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
29 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
30 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
31 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
32 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
33 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
34 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
35 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
36 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
37 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
38 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
39 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
40 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
41 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
42 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
43 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
44 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
45 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
46 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
47 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
48 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
49 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
50 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
51 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
52 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
53 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
54 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
55 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
56 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
57 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
58 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
59 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
60 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
61 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
62 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
63 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
64 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
65 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
66 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
67 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
68 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
69 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
70 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
71 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
72 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
73 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
74 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
75 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
76 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
77 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
78 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
79 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
80 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
81 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
82 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
83 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
84 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
85 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
86 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
87 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
88 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
89 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
90 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
91 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
92 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
93 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
94 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
95 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
96 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
97 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
98 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
99 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
100 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
101 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
102 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
103 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
104 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
105 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
106 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
107 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
108 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
109 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
110 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
111 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
112 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
113 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
114 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
115 xxx +0x8eeb18 -[RNSScreen findChildVCForConfigAndTrait:includingModals:] (RNSScreen.mm:1043:11)
116 xxx +0x8ef064 -[RNSScreen childViewControllerForHomeIndicatorAutoHidden] (RNSScreen.mm:1139:26)
117 UIKitCore +0x206598 -[UIViewController _effectiveHomeIndicatorAutoHiddenViewController]
118 UIKitCore +0x206580 -[UIViewController _effectiveHomeIndicatorAutoHiddenViewController]
119 UIKitCore +0x2064a0 -[_UISystemAppearanceManager updateHomeIndicatorAutoHidden]
120 UIKitCore +0x206440 ___59-[UIViewController setNeedsUpdateOfHomeIndicatorAutoHidden]_block_invoke_2
121 UIKitCore +0xdeea8 -[UIViewController _updateSystemAppearanceWithRecursionBlock:action:]
122 UIKitCore +0xdee0c -[UIViewController _updateSystemAppearanceWithRecursionBlock:action:]
123 UIKitCore +0x1b1698 -[UINavigationController pushViewController:transition:forceImmediate:]
124 UIKitCore +0x1b1358 -[UINavigationController pushViewController:animated:]
125 xxx +0x8f45f8 -[RNSScreenStackView setPushViewControllers:] (RNSScreenStack.mm:517:7)
126 xxx +0x8f4960 -[RNSScreenStackView updateContainer] (RNSScreenStack.mm:548:3)
127 xxx +0x8f479c __45-[RNSScreenStackView setPushViewControllers:]_block_invoke_2 (RNSScreenStack.mm:463:13)
128 UIKitCore +0x344f34 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
129 UIKitCore +0x2b343c -[_UIViewControllerTransitionContext _runAlongsideCompletions]
130 UIKitCore +0x2b24a8 -[_UIViewControllerTransitionContext completeTransition:]
131 UIKitCore +0x2b362c -[UITransitionView notifyDidCompleteTransition:]
132 UIKitCore +0x2b322c -[UITransitionView _didCompleteTransition:]
133 UIKitCore +0x106082c ___UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__
134 UIKitCore +0xce8d4 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:]
135 UIKitCore +0xcd830 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
136 UIKitCore +0xccf4c -[UIViewAnimationState animationDidStop:finished:]
137 UIKitCore +0xcd060 -[UIViewAnimationState animationDidStop:finished:]
138 QuartzCore +0x13620 CA::Layer::run_animation_callbacks(void*)
139 libdispatch.dylib +0x3ea8 __dispatch_client_callout
140 libdispatch.dylib +0x126a0 __dispatch_main_queue_drain
141 libdispatch.dylib +0x122f0 __dispatch_main_queue_callback_4CF
142 CoreFoundation +0x98c24 ___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
143 CoreFoundation +0x7a55c ___CFRunLoopRun
144 CoreFoundation +0x7f3e8 _CFRunLoopRunSpecific
145 GraphicsServices +0x1358 _GSEventRunModal
146 UIKitCore +0x39d6e4 -[UIApplication _run]
147 UIKitCore +0x39d348 _UIApplicationMain
148 xxx +0x70bc main (main.m:8:12)
149 dyld +0x15de8 start
Steps to reproduce
Sadly not entirely sure
Snack or a link to a repository
Screens version
3.22.1
React Native version
0.71.8
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Paper (Old Architecture)
Build type
Release mode
Device
Real device
Device model
any iPhone
Acknowledgements
Yes
Hey! 👋
It looks like you've omitted a few important sections from the issue template.
Please complete Snack or a link to a repository section.
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
Hi @adamivancza, have you found a solution for this crash? We have the same problem with CarPlay. I saw this comment of yours, have you tried if it also solves our problem?
@nicomontanari the second one doesn't seem to happen anymore for us. We've updated to 6.37.0 recently which might fixed this. But the first one is still happening, but very rarely. Didn't find a solution yet.
@adamivancza ok thank you 😥 If we find a solution I'll tell you! :)
@nicomontanari awesome, thank you :)
We are experiencing the same issue when trying to connect to CarPlay without opening the iPhone app. [RNSScreenWindowTraits enforceDesiredDeviceOrientation]_block_invoke
Not the best solution, but I finally decided to turn off react native screens in my project:
import { enableScreens } from 'react-native-screens';
enableScreens(false);
My app works now good in Carplay and in my iPhone.
Hi @adamivancza, thanks for submitting this issue! Yes, the problem definitely lies on screen orientation, since the stack trace you provided reveals the calls for the orientation-related methods. Is it possible to create a minimal reproduction that covers your specific case? If not, then I'll need more information about your environment - could you give me an overview of how your navigation stack is structured (also, are there nested stacks, how does your screen look like and what is the presentation of this screen, is this brownfield app? (React native loaded on a Fragment / only in subpart of view hierarchy)?
@mursang good catch. Just out of curiosity, do you use react-navigation in your app? I am afraid that if we would apply your change in our app it could crash
hey @nicomontanari,
yes, I am using react navigation:
"react-native": "0.71.13",
"@react-navigation/bottom-tabs": "6.5.8",
"@react-navigation/native": "6.1.7",
"@react-navigation/stack": "5.14.9",
"react-native-screens": "3.27.0",
and nothing seems to have changed in my app after applying that line of code :)
Hi @adamivancza, thanks for submitting this issue! Yes, the problem definitely lies on screen orientation, since the stack trace you provided reveals the calls for the orientation-related methods. Is it possible to create a minimal reproduction that covers your specific case? If not, then I'll need more information about your environment - could you give me an overview of how your navigation stack is structured (also, are there nested stacks, how does your screen look like and what is the presentation of this screen, is this brownfield app? (React native loaded on a Fragment / only in subpart of view hierarchy)?
@tboba I wasn't able to repro the app myself but I can share the breadcrumbs that bugsnag collects in case that helps. This is a fully react-native app.
app displays a full screen modal using react-navigation
then these are the further breadcrumbs from bugsnag. seems like app is backgrounded while the modal is being displayed. then I assume while the app is backgrounded the device orientation changes?
I can confirm that it also seems to happen for our users when the app is in the background:
We're seeing the first one over here as well (objectAtIndexedSubscript).
We are experiencing the same issue when trying to connect to CarPlay without opening the iPhone app. [RNSScreenWindowTraits enforceDesiredDeviceOrientation]_block_invoke
We got the same error when trying to open the CarPlay app with the iPhone app closed.
[CPTemplateApplicationScene requestGeometryUpdateWithPreferences:errorHandler:]: unrecognized selector sent to instance 0x12372f590
I'm not an objective-c expert, but I think I found the source of the bug.
In RNSScreenWindowTraits.mm the scene get type casted to UIWindowScene.
But when opening the CarPlay app, the scene at array[0] is in our case a CPTemplateApplicationScene
if (@available(iOS 16.0, *)) {
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = (UIWindowScene *)array[0];
UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:orientationMask];
[scene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError *_Nonnull error){}];
If I add a check like this before the above code the app is not crashing
if (![array[0] isKindOfClass:[UIWindowScene class]]) { return; }
Thanks for doing the leg work on this @casperolesen. That check makes the app work correctly on CarPlay, but we need to add additional handling for when an app is opened on device after it is opened on CarPlay.
Here is a complete patch for the orientation issue.
diff --git a/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm b/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm
index e8a717e..ea3b2a7 100644
--- a/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm
+++ b/node_modules/react-native-screens/ios/RNSScreenWindowTraits.mm
@@ -178,7 +178,21 @@
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_0
if (@available(iOS 16.0, *)) {
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
- UIWindowScene *scene = (UIWindowScene *)array[0];
+
+ // when an app supports multiple scenes (e.g. CarPlay), it is possible that
+ // UIWindowScene is not the first scene, or it may not be present at all
+ UIWindowScene *scene = nil;
+ for (id connectedScene in array) {
+ if ([connectedScene isKindOfClass:[UIWindowScene class]]) {
+ scene = connectedScene;
+ break;
+ }
+ }
+
+ if (scene == nil) {
+ return;
+ }
+
UIWindowSceneGeometryPreferencesIOS *geometryPreferences =
[[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:orientationMask];
[scene requestGeometryUpdateWithPreferences:geometryPreferences
Hi @adamivancza, could you check if the patch submitted above fixes both of the crashes?
yep @tboba - will try it out and let you know. I'll need ~2 weeks to check on Bugsnag if it is all good.
Re-opening it, since the PR had a fixes comment, but I hope this will be closed soon 😅
Hi @adamivancza! Do you have any updates, regarding this issue?
hey @tboba! sooo sorry but I forgot about this 😅 I've updated our version to 3.30.0 which has the same fix. We will release this update to our users next Monday so I can give you updates sometime next week!