digidem / comapeo-mobile

The next version of Mapeo mobile
GNU General Public License v3.0
5 stars 1 forks source link

Closing app while track is active causes several errors #635

Open achou11 opened 2 months ago

achou11 commented 2 months ago

Describe the bug

In development, I'm getting this error when running the reproduction steps listed below:

 ERROR  Your app just crashed. See the error below.
java.lang.IndexOutOfBoundsException: index=1 count=0
  android.view.ViewGroup.addInArray(ViewGroup.java:5424)
  android.view.ViewGroup.addViewInner(ViewGroup.java:5317)
  android.view.ViewGroup.addView(ViewGroup.java:5124)
  android.view.ViewGroup.addView(ViewGroup.java:5064)
  com.facebook.react.uimanager.ViewGroupManager.addView(ViewGroupManager.java:38)
  com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:533)
  com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren(ReanimatedNativeHierarchyManager.java:300)
  com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:217)
  com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:926)
  com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1037)
  com.facebook.react.uimanager.UIViewOperationQueue.-$$Nest$mflushPendingBatches(Unknown Source:0)
  com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded(UIViewOperationQueue.java:995)
  com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:29)
  android.os.Handler.handleCallback(Handler.java:959)
  android.os.Handler.dispatchMessage(Handler.java:100)
  android.os.Looper.loopOnce(Looper.java:232)
  android.os.Looper.loop(Looper.java:317)
  android.app.ActivityThread.main(ActivityThread.java:8592)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

When re-opening the app, I get an app error that says the following (and the app doesn't actually load):

 ERROR  TypeError: startDate.getTime is not a function (it is undefined)

This error is located at:
    in TrackTimerContextProvider (at AppProviders.tsx:54)
    in RNGestureHandlerRootView (at GestureHandlerRootView.android.tsx:21)
    in GestureHandlerRootView (at AppProviders.tsx:53)
    in RNCSafeAreaProvider (at SafeAreaContext.tsx:92)
    in SafeAreaProvider (at AppProviders.tsx:52)
    in QueryClientProvider (at AppProviders.tsx:51)
    in IntlProvider (at IntlContext.tsx:40)
    in IntlProvider (at AppProviders.tsx:50)
    in AppProviders (at App.tsx:77)
    in App (created by RootApp)
    in ReactNativeProfiler (created by RootApp)
    in RCTView (at View.js:116)
    in View (created by __Sentry.TouchEventBoundary)
    in __Sentry.TouchEventBoundary (created by RootApp)
    in RootApp (at withDevTools.js:18)
    in withDevTools(RootApp) (at renderApplication.js:57)
    in RCTView (at View.js:116)
    in View (at AppContainer.js:127)
    in RCTView (at View.js:116)
    in View (at AppContainer.js:155)
    in AppContainer (at renderApplication.js:50)
    in main(RootComponent) (at renderApplication.js:67), js engine: hermes

Seems like the only way to recover is to clear the app storage (not even just the cache)...

To Reproduce

Under the assumption that you have tracks feature enabled...

  1. Start a track
  2. Start creating an observation
  3. Close the app

Seems like the issue doesn't occur if 2 is omitted.

cimigree commented 2 months ago

I got the same error but without starting to create an observation... And I didn't close the app, just put it in the background

ErikSin commented 1 month ago

Update on my progress. The issue is happening very indeterminately. I have not figured out how to recreate the error consistently.

When the error does happen, it is consistently the error that andrew has logged above.

Im going to try building an apk next to see if it has anything to do with expo, and expo rebundling

ErikSin commented 1 month ago

I have determined what is causing the bug (but don't fully understand the underlying architecture). But its related to our hot-reload not properly working.

So the bug happens in the dev environments when android is rebundled. With hot-reload, it shouldn't rebundle, but our hot reloading isnt consistently working. When we open and close the app, sometime (but not all time), the app rebundles, and that causes the tracks to crash.

To confirm, i built an apk, and I have not been able to reproduce this bug in production.

Because it is not happening in production, I am going to de-priortize this bug. And I think that the fix for this bug is actually going to be a fix for hot-reload