rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.22k stars 839 forks source link

[Android] AddLayer crash on startup race condition #462

Closed kristfal closed 4 years ago

kristfal commented 4 years ago

Describe the bug After upgrading from 7.0.4 to 7.0.5, we started to see a significant (about 5%) crash amongst our users.

Stack trace:

com.mapbox.rctmgl.components.mapview.RCTMGLMapView.addFeature

Java.lang.IndexOutOfBoundsException: Invalid index 2, size is 0

java.util.ArrayList.throwIndexOutOfBoundsException ArrayList.java:255
java.util.ArrayList.add ArrayList.java:147
com.mapbox.rctmgl.components.mapview.RCTMGLMapView.addFeature RCTMGLMapView.java:212
com.mapbox.rctmgl.components.mapview.RCTMGLMapViewManager.addView RCTMGLMapViewManager.java:77
com.mapbox.rctmgl.components.mapview.RCTMGLMapViewManager.addView RCTMGLMapViewManager.java:39
com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren NativeViewHierarchyManager.java:438
com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute UIViewOperationQueue.java:227
com.facebook.react.uimanager.UIViewOperationQueue$1.run UIViewOperationQueue.java:917
com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches UIViewOperationQueue.java:1025
com.facebook.react.uimanager.UIViewOperationQueue.access$2600 UIViewOperationQueue.java:46
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded UIViewOperationQueue.java:1085
com.facebook.react.uimanager.GuardedFrameCallback.doFrame GuardedFrameCallback.java:29
com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame ReactChoreographer.java:166
com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame ChoreographerCompat.java:84
android.view.Choreographer$CallbackRecord.run Choreographer.java:812
android.view.Choreographer.doCallbacks Choreographer.java:614
android.view.Choreographer.doFrame Choreographer.java:583
android.view.Choreographer$FrameDisplayEventReceiver.run Choreographer.java:800
android.os.Handler.handleCallback Handler.java:733
android.os.Handler.dispatchMessage Handler.java:95
android.os.Looper.loop Looper.java:146
android.app.ActivityThread.main ActivityThread.java:5487
java.lang.reflect.Method.invokeNative Method.java
java.lang.reflect.Method.invoke Method.java:515
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run ZygoteInit.java:1283
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1099
dalvik.system.NativeStart.main NativeStart.java

Likely caused by:

https://github.com/react-native-mapbox-gl/maps/commit/3ef504d20c2fc2e69d9a84260af93b0eb915bcd6#diff-83bd90811e16ee14c9357ca5dd70f50cR395

My best guess is that since we defer adding queued features to OnStyleLoaded, indexes are not correct when new layers are added in the time between onMapReady and OnStyleLoaded, which in turn is causing crashes.

@frankrowe this was your PR. Do you think this sounds reasonable? What was the reason for moving addQueuedFeatures in OnStyleLoaded? What do you think about moving it back to onMapReady?

To Reproduce Hard to do due to the nature of the bug

Versions (please complete the following information):

WhiteHatTux commented 4 years ago

I get this error every time, when starting the example application in my emulator when running the example from master branch.

kristfal commented 4 years ago

@frankrowe any comment on this?

abumubaarak commented 1 year ago

I am still getting the crash on Android

Exception java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.add (ArrayList.java:483) at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.addFeature (RCTMGLMapView.kt:273) at com.mapbox.rctmgl.components.mapview.RCTMGLMapViewManager.addView (RCTMGLMapViewManager.kt:50) at com.mapbox.rctmgl.components.mapview.RCTMGLMapViewManager.addView (RCTMGLMapViewManager.kt:26) at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren (NativeViewHierarchyManager.java:533) at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren (ReanimatedNativeHierarchyManager.java:306) at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute (UIViewOperationQueue.java:217) at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:915) at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:1026) at com.facebook.react.uimanager.UIViewOperationQueue.access$2600 (UIViewOperationQueue.java:47) at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded (UIViewOperationQueue.java:984) at com.facebook.react.bridge.GuardedRunnable.run (GuardedRunnable.java:31) at android.os.Handler.handleCallback (Handler.java:938) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:241) at android.os.Looper.loop (Looper.java:342) at android.app.ActivityThread.main (ActivityThread.java:8117) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:583) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1045)