react-native-screens: RNScreenContainer crashes on iOS while in the background

Description

RNScreenContainer crashes, as per below, while the app is in the background. The error happens at random times (i.e. not immediately before/after backgrounding the app), presumably when our background task kicks in. I unfortunately haven’t been able to reproduce yet…

OS Version: iOS 14.4.2 (18D70)
Report Version: 104

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 0

Application Specific Information:
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

Thread 0 Crashed:
0   CoreFoundation                  0x30881986c         __exceptionPreprocess
1   libobjc.A.dylib                 0x33296ac4c         objc_exception_throw
2   CoreFoundation                  0x308889e18         _CFThrowFormattedException
3   CoreFoundation                  0x3088872fc         -[__NSArrayM insertObject:atIndex:].cold.1
4   CoreFoundation                  0x3086f6b8c         -[__NSArrayM insertObject:atIndex:]
5   UIKitCore                       0x30c9c1518         -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:]
6   GreenTriangle                   0x202faf204         -[RNSScreenContainerView attachScreen:atIndex:] (RNSScreenContainer.m:144)
7   GreenTriangle                   0x202faf72c         -[RNSScreenContainerView updateContainer] (RNSScreenContainer.m:189)
8   GreenTriangle                   0x202fafe58         __41-[RNSScreenContainerManager markUpdated:]_block_invoke (RNSScreenContainer.m:276)

Package versions

react-native-screens@3.2.0 react-native@0.64.1 react@17.0.1

It has been happening since our previous release, on: react-native-screens@2.17.1 react-native@0.63.4 react@16.13.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 21 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@WoLewicki Sorry, I am not getting this issue on my local machine but it is getting by some users on production

If it help, we are also experiencing the exact same crash.

Same as above most crashes happen after app comes to foreground from background.

We are currently using: react-navigation/bottom-tabs:@5.11.8 react-navigation/native@^5.9.3 react-navigation/stack@^5.14.3 react-native-screens@3.1.1 react-native@0.64.0 react@17.0.1

Edit: we’re seeing another issue related to this

EXC_BAD_ACCESS Exception 1, Code 458777608, Subcode 8 > Attempted to dereference garbage pointer 0xa5991b586408.

@fedeerbes React Navigation documentation recommends conditionally removing screens but not stacks eg.

state.userToken == null ? (
  <>
    <Stack.Screen name="SignIn" component={SignInScreen} />
    <Stack.Screen name="SignUp" component={SignUpScreen} />
    <Stack.Screen name="ResetPassword" component={ResetPassword} />
  </>
) : (
  <>
    <Stack.Screen name="Home" component={HomeScreen} />
    <Stack.Screen name="Profile" component={ProfileScreen} />
  </>
);

Quote from docs

If you have both your login-related screens and rest of the screens in Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators.

See “Best practices when nesting” in React Navigation documentation and the “Authentication flow” if you have the time. Cheers!

I am using RN@0.66, reanimated@2.3.1, and react-native-screens@3.10.1 and having the same issue from the sentry log but it is triggering from react-native-screens

EXC_BAD_ACCESS: __reanimatedHostObjectRef >
Attempted to dereference garbage pointer 0x8.
  OnShobbak           0x100ea9264  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed23ec  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed2ed8  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed2ed8  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed23ec  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100eb16e8  folly::Try<T>::throwUnlessValue
  OnShobbak           0x101018138  _ZN5folly6detail8function9execSmallIZNS_7futures6detail4CoreINS_4UnitEE11setCallbackIZNS4_10FutureBaseIS6_E18thenImplementationIZNRS_6FutureIS6_E3viaENS_8Executor9KeepAliveISE_EEEUlOSG_ONS_3TryIS6_EEE_NS4_25tryExecutorCallableResultIS6_SL_vEEEENSt3__19e...
  hermes              0x1027d90f4  facebook::hermes::debugger::Debugger::jsiValueFromHermesValue
  hermes              0x1027d8aa0  facebook::hermes::debugger::Debugger::jsiValueFromHermesValue
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e63ec  facebook::jsi::JSError::~JSError
  hermes              0x10285a954  facebook::jsi::JSError::~JSError
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e7330  facebook::jsi::JSError::~JSError
  hermes              0x1028013ec  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e7330  facebook::jsi::JSError::~JSError
  hermes              0x1028013ec  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e684c  facebook::jsi::JSError::~JSError
  hermes              0x1028887a0  facebook::jsi::JSError::~JSError
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e684c  facebook::jsi::JSError::~JSError
  hermes              0x1028887a0  facebook::jsi::JSError::~JSError
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e7330  facebook::jsi::JSError::~JSError
  hermes              0x1027d1aac  facebook::hermes::HermesRuntime::rootsListLength
  OnShobbak           0x10101706c  _ZN5folly6detail8function9execSmallIZNS_7futures6detail4CoreINS_4UnitEE11setCallbackIZNS4_10FutureBaseIS6_E18thenImplementationIZNRS_6FutureIS6_E3viaENS_8Executor9KeepAliveISE_EEEUlOSG_ONS_3TryIS6_EEE_NS4_25tryExecutorCallableResultIS6_SL_vEEEENSt3__19e...
  OnShobbak           0x1010481f8  folly::exception_wrapper::InPlace<T>::get_exception_ptr_
  OnShobbak           0x10104805c  folly::exception_wrapper::InPlace<T>::get_exception_ptr_
  OnShobbak           0x100ed927c  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x1010455f8  folly::exception_wrapper::InPlace<T>::get_exception_ptr_
  OnShobbak           0x100ff0238  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x100f3d278  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x100f496e0  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x100f49494  facebook::react::JSIExecutor::defaultTimeoutInvoker
  CoreFoundation      0x1806be9d0  __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
  CoreFoundation      0x1806bf8cc  __CFRunLoopDoBlocks
  CoreFoundation      0x180657c2c  __CFRunLoopRun
  CoreFoundation      0x18066b464  CFRunLoopRunSpecific
  OnShobbak           0x100f324d4  facebook::react::JSIExecutor::defaultTimeoutInvoker
  Foundation          0x181ed7408  __NSThread__start__
  libsystem_pthread   0x1f10bb9a0  _pthread_start

image

@kacperkapusciak in my case at least, I was conditionally removing the entire navigator. In either case: I would hope that a crash is unwarranted, that it would be better to at least “catch” the underlying behavior and throw an error…?

In my case, this error went away, after:

  • removing all Alerts that triggered in the background
  • removing a flow where the navigator would get destroyed