question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reloading Via React Native Debug Menu Causes Crash when Realm is installed

See original GitHub issue

Description

Looks like another incarnation of https://github.com/software-mansion/react-native-reanimated/issues/1285 Was happening on my project when tried to add reanimated 2 (just plainly calling <Animated.View />). I’ve tracked it down to a possible conflict with another dependancy: realmjs. Below are the steps to reproduce it from reanimated 2 playground

Screenshots

image

Steps To Reproduce

  1. checkout reanimated 2 playground
  2. upgrade react native to 0.63.3
  3. add realm: yarn add realm
  4. npx pod-install
  5. run in simulator and try to refresh with cmd+R

Package versions

  • React: 16.13.1
  • React Native: 0.63.3
  • React Native Reanimated: 2.0.0-alpha.8
  • NodeJS: v14.9.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
mattijsfcommented, Mar 7, 2021

We’re in the process of removing realm-js, mainly due to lack of Hermes support and this is another…

These lines are causing the crash:

JSCRuntime::~JSCRuntime() {
  // On shutting down and cleaning up: when JSC is actually torn down,
  // it calls JSC::Heap::lastChanceToFinalize internally which
  // finalizes anything left over.  But at this point,
  // JSValueUnprotect() can no longer be called.  We use an
  // atomic<bool> to avoid unsafe unprotects happening after shutdown
  // has started.
  ctxInvalid_ = true;
  JSGlobalContextRelease(ctx_);
#ifndef NDEBUG
  assert(
      objectCounter_ == 0 && "JSCRuntime destroyed with a dangling API object");
  assert(
      stringCounter_ == 0 && "JSCRuntime destroyed with a dangling API string");
#endif
}

I guess both modules are tinkering somewhat with JSI and are causing this problem.

I’ve added the following lines to Podfile to prevent the app from crashing upon reload (in our case temporarily). Should be used with care though! As obviously something is going wrong on either Realm or Reanimated v2’s side and this error hints towards a memory issue/leak. The NDEBUG flag within the Realm-jsi module is only used for reference counting.

installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        if target.name == "React-jsi"
          puts "*** Patching React-jsi pod..."
          puts "***"
          puts "*** - Adding NDEBUG=1 to silence the 'JSCRuntime destroyed with a dangling API object' crash upon reload"
          puts "***"
          puts "*** This is cause by realm-js and reanimated v2 being loaded both at runtime."
          puts "*** It's recommended to remove realmjs as it is also incompatible with Hermes."
          puts "*** After which this workaround can be removed from Podfile."
          puts "*** Done"
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'NDEBUG=1'
        end
      end
    end
3reactions
enigmabluecommented, Aug 13, 2021

Have the same problem, is there any workaround or planned fix for this? Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm: create causing a crash within android (react-native)
Please perform some troubleshooting by stepping through your code, line by line to determine which line is crashing and update the question with ......
Read more >
Reloading Via React Native Debug Menu Causes Crash when ...
Reloading Via React Native Debug Menu Causes Crash when Realm is installed.
Read more >
Realm: Create reactive mobile apps in a fraction of the time
Run react-native run-ios to rebuild the whole thing. Chrome Debugging is slow. We are aware of this. The reason for this is that...
Read more >
Using Hermes - React Native
Edit your android/app/gradle.properties file and make sure hermesEnabled is true: # Use this property to enable or disable the Hermes JS engine.
Read more >
In iOS 15, when the app is restarted, it immediately crashes.
After the iOS 15 update, the following process causes the app to die. ... issue in an iOS react-native app after iOS 15...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found