React-native-navigation: React Native Navigation Fatal Exception: Tried to create view after it has already been destroyed

Created on 8 Mar 2019  路  10Comments  路  Source: wix/react-native-navigation

Issue Description::

I am working on React native application and using React Native Navigation for routing.

Sometimes my app crash on Android as I have crashlytics installed So I verified crashes using Firebase crash logs. I am getting this error log inside crashlytics::

Fatal Exception: java.lang.RuntimeException: Tried to create view after it has already been destroyed at com.reactnativenavigation.viewcontrollers.ViewController.getView(ViewController.java:161) 
at com.reactnativenavigation.viewcontrollers.ParentController.getView(ParentController.java:60)
at com.reactnativenavigation.viewcontrollers.stack.StackController.lambda$push$4(StackController.java:172)
at com.reactnativenavigation.viewcontrollers.stack.-$$Lambda$StackController$06hFigyLWXXMellTVVP0d0y7blk.run(Unknown Source:8)
at com.reactnativenavigation.anim.NavigationAnimator$1.onAnimationEnd(NavigationAnimator.java:64) at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:552)
at android.animation.AnimatorSet.endAnimation(AnimatorSet.java:1294)
at android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1079)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1170)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:806)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

This is only happening inside Android application. I am not able to reproduce this case again, sometimes it occurs automatically. Most of the time it occurs when child screen is comes over the parent screen.

Code::

Navigation.push(this.props.componentId, {
                component: {
                    id: screenId,
                    name: screenName,
                    passProps: props,
                    options: options
                }
            });

Navigation.popToRoot(this.props.componentId);

I am using ::

  • react native version :: 0.58.6
  • react native navigation :: 2.12.0
Android acceptebug 馃彋 stale

Most helpful comment

@Zaporozhec7 Thanks for the detailed comment! This should be fixed by #5162, published in 2.21.0

All 10 comments

I have same issue on RN 0.57.8 and RNN v.2.12.0

Seeing the same crashes

same issue here any update?

We are still seeing this on 2.16.0

I do not work with native code, and do not know Java, but I tried do some debugging.
In my case exception thrown when called setRoot() with layout that contain SideMenu. But only when it set again (not first time):

  1. setRoot() with layout which contain SideMenu [All fine here]
  2. setRoot() with new layout, without SideMenu [All fine here]
  3. setRoot() with layout which contain SideMenu (same as 1.) [Exception thrown here]

I found that problem (in my case) in ChildControllersRegistry. On step 2 above it sometimes contain ChildController of SideMenuRight, that should not be there, because it destroyed earlier.

Somehow ChildControllersRegistry, that shared between child controllers (if I understand right), sometimes not cleaned properly from previously destroyed child controllers.

I do not work with native code, and do not know Java, but I tried do some debugging.
In my case exception thrown when called setRoot() with layout that contain SideMenu. But only when it set again (not first time):

  1. setRoot() with layout which contain SideMenu [All fine here]
  2. setRoot() with new layout, without SideMenu [All fine here]
  3. setRoot() with layout which contain SideMenu (same as 1.) [Exception thrown here]

I found that problem (in my case) in ChildControllersRegistry. On step 2 above it sometimes contain ChildController of SideMenuRight, that should not be there, because it destroyed earlier.

Somehow ChildControllersRegistry, that shared between child controllers (if I understand right), sometimes not cleaned properly from previously destroyed child controllers.

Try adding

if (children.size() == 2) {
    children.pop();
}

after

children.pop()

in ChildControllersRegistry.java.

Result:

    public void onViewDisappear(ChildController child) {
        if (isTopChild(child)) {
            children.pop();
            if (children.size() == 2) {
              children.pop();
            }
            if (!children.isEmpty()) children.peek().onViewBroughtToFront();
        } else {
            children.remove(child);
        }
    }

Works for me.
The problem is in the extra child in the array after the destruction.
I do not know Java, please author to fix it correctly.
Thanks for the module, it is the best looking at the problem!

Sorry for my english.

Any updates for this? I got the same problem in 2.18.5

@Zaporozhec7 Thanks for the detailed comment! This should be fixed by #5162, published in 2.21.0

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

The issue has been closed for inactivity.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhanguangao picture zhanguangao  路  3Comments

nbolender picture nbolender  路  3Comments

viper4595 picture viper4595  路  3Comments

bdrobinson picture bdrobinson  路  3Comments

henrikra picture henrikra  路  3Comments