I am rendering a camera screen using a stack navigator
function BottomNavigationBar() {
return (
<NavigationContainer>
<StackNavigator.Navigator
screenOptions={{
style: {backgroundColor: NAV_BAR_BACKGROUND_COLOR},
headerShown: false,
}}
>
<StackNavigator.Screen name={"Home"} component={HomeTabs}/>
<StackNavigator.Screen name={"Camera"} component={CameraScreen} options={{unmountOnBlur: true}}/>
</StackNavigator.Navigator>
</NavigationContainer>
)
}
but when I switch back and fourth between the home tabs and camera screen I sometimes get an app crash with the following stack trace:
2023-04-11 10:53:52.961753-0400 Metis[10278:3212869] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x281983390> was mutated while being enumerated.'
*** First throw call stack:
(0x1c2bace38 0x1bbd3b8d8 0x1c2d19418 0x1c4d8cc1c 0x1c4e07c14 0x1c4e04a08 0x102bfb614 0x1c4e045fc 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c2c0e254 0x1c2c0e3c4 0x1bbd550b0 0x1bbd2a2a8 0x1bbd33994 0x1c4f7cf40 0x1c4e04874 0x1c4f7c9f4 0x1bbd255d8 0x1bbd28f80 0x1c4f1b7f0 0x1c4f1b710 0x1c4f1b61c 0x1c4db6a08 0x1c527c108 0x1c53ca5b0 0x1c5a19310 0x1c5a184dc 0x1c2c78f24 0x1c2c852fc 0x1c2c091c0 0x1c2c1eb7c 0x1c2c23eb0 0x1fce19368 0x1c5119668 0x1c51192cc 0x102bf4b5c 0x1e151c960)
libc++abi: terminating with uncaught exception of type NSException
and the origanl exception backtrace looks related to unmounting the expo camera view:
Thread#0 0x00000001c2bace38 in __exceptionPreprocess ()
#1 0x00000001bbd3b8d8 in objc_exception_throw ()
#2 0x00000001c2d19418 in __NSFastEnumerationMutationHandler ()
#3 0x00000001c4d8cc1c in _makeSubTreePerformSelector ()
#4 0x00000001c4e07c14 in __UIViewWasRemovedFromSuperview ()
#5 0x00000001c4e04a08 in -[UIView(Hierarchy) removeFromSuperview] ()
#6 0x0000000102bfb614 in -[EXCamera removeFromSuperview] at /Users/doms/ReactNativeMetis/Metis/node_modules/expo-camera/ios/EXCamera/EXCamera.m:129
#7 0x00000001c4e045fc in -[UIView dealloc] ()
#8 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#9 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#10 0x00000001bbd550b0 in _object_remove_associations ()
#11 0x00000001bbd2a2a8 in objc_destructInstance ()
#12 0x00000001bbd33994 in _objc_rootDealloc ()
#13 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#14 0x00000001c4e04874 in -[UIView dealloc] ()
#15 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#16 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#17 0x00000001bbd550b0 in _object_remove_associations ()
#18 0x00000001bbd2a2a8 in objc_destructInstance ()
#19 0x00000001bbd33994 in _objc_rootDealloc ()
#20 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#21 0x00000001c4e04874 in -[UIView dealloc] ()
#22 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#23 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#24 0x00000001bbd550b0 in _object_remove_associations ()
#25 0x00000001bbd2a2a8 in objc_destructInstance ()
#26 0x00000001bbd33994 in _objc_rootDealloc ()
#27 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#28 0x00000001c4e04874 in -[UIView dealloc] ()
#29 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#30 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#31 0x00000001bbd550b0 in _object_remove_associations ()
#32 0x00000001bbd2a2a8 in objc_destructInstance ()
#33 0x00000001bbd33994 in _objc_rootDealloc ()
#34 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#35 0x00000001c4e04874 in -[UIView dealloc] ()
#36 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#37 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#38 0x00000001bbd550b0 in _object_remove_associations ()
#39 0x00000001bbd2a2a8 in objc_destructInstance ()
#40 0x00000001bbd33994 in _objc_rootDealloc ()
#41 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#42 0x00000001c4e04874 in -[UIView dealloc] ()
#43 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#44 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#45 0x00000001bbd550b0 in _object_remove_associations ()
#46 0x00000001bbd2a2a8 in objc_destructInstance ()
#47 0x00000001bbd33994 in _objc_rootDealloc ()
#48 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#49 0x00000001c4e04874 in -[UIView dealloc] ()
#50 0x00000001c2c0e254 in __RELEASE_OBJECTS_IN_THE_ARRAY__ ()
#51 0x00000001c2c0e3c4 in -[__NSArrayM dealloc] ()
#52 0x00000001bbd550b0 in _object_remove_associations ()
#53 0x00000001bbd2a2a8 in objc_destructInstance ()
#54 0x00000001bbd33994 in _objc_rootDealloc ()
#55 0x00000001c4f7cf40 in -[UIResponder dealloc] ()
#56 0x00000001c4e04874 in -[UIView dealloc] ()
#57 0x00000001c4f7c9f4 in -[UIViewController dealloc] ()
#58 0x00000001bbd255d8 in AutoreleasePoolPage::releaseUntil(objc_object**) ()
#59 0x00000001bbd28f80 in objc_autoreleasePoolPop ()
#60 0x00000001c4f1b7f0 in -[_UIAfterCACommitBlock run] ()
#61 0x00000001c4f1b710 in -[_UIAfterCACommitQueue flush] ()
#62 0x00000001c4f1b61c in _runAfterCACommitDeferredBlocks ()
#63 0x00000001c4db6a08 in _cleanUpAfterCAFlushAndRunDeferredBlocks ()
#64 0x00000001c527c108 in _UIApplicationFlushCATransaction ()
#65 0x00000001c53ca5b0 in _UIUpdateSequenceRun ()
#66 0x00000001c5a19310 in schedulerStepScheduledMainSection ()
#67 0x00000001c5a184dc in runloopSourceCallback ()
#68 0x00000001c2c78f24 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#69 0x00000001c2c852fc in __CFRunLoopDoSource0 ()
#70 0x00000001c2c091c0 in __CFRunLoopDoSources0 ()
#71 0x00000001c2c1eb7c in __CFRunLoopRun ()
#72 0x00000001c2c23eb0 in CFRunLoopRunSpecific ()
#73 0x00000001fce19368 in GSEventRunModal ()
#74 0x00000001c5119668 in -[UIApplication _run] ()
#75 0x00000001c51192cc in UIApplicationMain ()
#76 0x0000000102bf4b5c in main at /Users/doms/ReactNativeMetis/Metis/ios/Metis/main.m:7
#77 0x00000001e151c960 in start ()
I added options={{unmountOnBlur: true}
to the camera screen stack but it made no difference.