rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
822 stars 87 forks source link

Crash while unwrapping coordinator in NavigationRouter #91

Open Steffenberg opened 1 year ago

Steffenberg commented 1 year ago

Hello,

I encountered an AppCrash in the "coordinator" getter of NavigationRouter due to the force cast on the type.

When bringing back the App from background I sometimes get: #6 (null) in swift_dynamicCast ()

I am calling it this way (after unwrapping the router safely): _ = overviewRouter.coordinator.customPopToRoot()

Stacktrace:

0 (null) in __pthread_kill () 6 (null) in swiftdynamicCast () 7 0x000000010325a530 in NavigationRouter.coordinator.getter () 8 0x0000000102f8d720 in specialized NavService.goToOverviewRoot() 9 0x000000010370ab20 in LifecycleService.reactOnStatusChange() 10 0x000000010370a92c in LifecycleService.updateTo(state:) 11 (null) in protocol witness for LifecycleServiceType.updateTo(state:) in conformance LifecycleService () 12 0x00000001030183dc in App.handleAppState(:) 13 (null) in partial apply for closure 2 in closure 1 in App.body.getter ()

Most likely because of the force cast of the weakReference in NavigationRouter.coordinator. Did you ever encounter this problem or have an idea how to solve it (other than making coordinator optional)?

Best regards Steffen

LePips commented 1 year ago

What are you attempting to do? Do you have a small sample to replicate?

Steffenberg commented 1 year ago

Thank you for your reply

Easily said I just want to go back to the root view on my "OverviewCoordinator" which just has the posibility of showing different child Coordinators. The OverviewCoordinator has a bit of a stage management system, this is why I have the custom "popToRoot"-Method changing the state before executing the navigation.

The thing is that it is embedded in a more complex operation and sample code might be a bit hard to extract but I will try to. Another problem is I was not able to reproduce it myself but our customer had it crashing several times (the log I provided are taken from Testflight directly).

Long story short I will try to provide a sample today/tomorrow, not guaranteeing it can really reproduce it :-/