sockeqwe / mosby-conductor

Plugin for conductor to integrate Mosby
Apache License 2.0
131 stars 22 forks source link

NPE on presenter.destroy() in MviConductorLifecycleListener postDestroy() #38

Open abyrnes opened 6 years ago

abyrnes commented 6 years ago

I found the following crasher. No repro steps unfortunately. But hopefully someone has an idea as to why it's happening:

com.hannesdorfmann.mosby3.MviConductorLifecycleListener.postDestroy (MviConductorLifecycleListener.java:133)
  com.bluelinelabs.conductor.Controller.performDestroy (Controller.java:1076)
  com.bluelinelabs.conductor.Controller.removeViewReference (Controller.java:972)
  com.bluelinelabs.conductor.Controller.destroy (Controller.java:1097)
  com.bluelinelabs.conductor.Controller.destroy (Controller.java:1082)
  com.bluelinelabs.conductor.Backstack.pop (Backstack.java:61)
  com.bluelinelabs.conductor.Backstack.popAll (Backstack.java:82)
  com.bluelinelabs.conductor.Router.destroy (Router.java:220)
  com.bluelinelabs.conductor.ControllerHostedRouter.destroy (ControllerHostedRouter.java:88)
  com.bluelinelabs.conductor.Controller.destroy (Controller.java:1093)
  com.bluelinelabs.conductor.Controller.activityDestroyed (Controller.java:859)
  com.bluelinelabs.conductor.Router.onActivityDestroyed (Router.java:558)
  com.bluelinelabs.conductor.ActivityHostedRouter.onActivityDestroyed (ActivityHostedRouter.java:61)
  com.bluelinelabs.conductor.internal.LifecycleHandler.destroyRouters (LifecycleHandler.java:209)
  com.bluelinelabs.conductor.internal.LifecycleHandler.onDestroy (LifecycleHandler.java:160)
  android.app.Fragment.performDestroy (Fragment.java:2587)
abyrnes commented 6 years ago

I suppose this could be related to #36

sockeqwe commented 6 years ago

Thanks for reporting. Yes it might be related to #36 or to #26

I'm not sure how this can happen, because it seems that presenter is null. Do you have a controller that doesn't have a UI (returning null from Controller.onCreateView())? Or maybe this happens if the user clicks back button fast enough before the View has been created because Presenter gets created after Controller.onCreateView().

Any idea how to reproduce this?

abyrnes commented 6 years ago

I've been able to resolve the issue on my side: We had a case where a child router was being used and the root was being set without checking if it already had a root after process death. Simply making sure that the root was only being set if necessary fixed the problem.

Not sure if any extra action should be taken here

Anfet commented 4 years ago

If possible I can bump up this topic.

I have an interesting situation. ViewPagerControllerA > PageA pushes ViewPagerControllerB > Page B ... Activity is killed (Dunno how it happens, but I reproduced it by setting "kill activities" in developer options) All controllers are being destroyed .... Activity is restored ... Attempt to invoke interface method 'void com.hannesdorfmann.mosby3.mvi.MviPresenter.destroy()' on a null object reference Becase view hierarchy is restoring to ViewPagerControllerB, while trying to remove ViewPagerControllerA which doesn't exist anymore. Am I correct in this assumption?

I guess presenter?.destroy() would do?