react-native-maps icon indicating copy to clipboard operation
react-native-maps copied to clipboard

Android Crashes java.lang.IndexOutOfBoundsException: Index: 235, Size: 225

Open mattproch opened this issue 8 months ago • 17 comments

Summary

Hey, on the initial mount, android crashes. It starts in the 1.21.0 version and it is still present in the 1.23.7 version.

I get this error:

Image

Reproducible sample code

<MapView
        ref={map}
        superClusterRef={superCluster}
        initialRegion={
          location.latitude && location.longitude
            ? {
                latitude: location.latitude,
                longitude: location.longitude,
                latitudeDelta: DEFAULT_LAT_DELTA,
                longitudeDelta: DEFAULT_LNG_DELTA,
              }
            : appConfig.MAP.INITIAL_REGION
        }
        toolbarEnabled={false}
        animationEnabled={false}
        showsUserLocation={!!permissions.locationGranted}
        showsMyLocationButton={false}
        style={styles.map}
        radius={40}
        onPress={onMapPress}
        onPanDrag={onMapDrag}
        renderCluster={renderCluster}
        googleRenderer="LATEST"
        {...otherProps}
      >
        {markers}
      </MapView>


interface Props {
  coordinate: { latitude: number; longitude: number };
  onMarkerPress?: (markerRef: MapMarker | null) => void;
}

const Marker = ({ coordinate, onMarkerPress }: Props) => {
  const ref = useRef<MapMarker>(null);

  return (
    <DefaultMarker
      ref={ref}
      centerOffset={{ x: 0.0, y: -26 }}
      coordinate={coordinate}
      tracksViewChanges={false}
      image={{ uri: appConfig.MAP.MARKER_IMAGE }}
      style={styles.marker}
      pinColor={COLORS['solid/blue']}
      zIndex={1}
      onPress={() => {
        if (onMarkerPress) {
          onMarkerPress(ref.current);
        }
      }}
    ></DefaultMarker>
  );
};

export default memo(Marker);

const styles = StyleSheet.create({
  marker: {
    width: 43,
    height: 52,
  },
});

Steps to reproduce

I also use "react-native-map-clustering" version 3.4.2.

Expected result

App not crashing

Actual result

App crashes

React Native Maps Version

1.23.7

What platforms are you seeing the problem on?

Android

React Native Version

0.76.9

What version of Expo are you using?

SDK 52

Device(s)

Honor, Android 9

Additional information

No response

mattproch avatar May 11 '25 21:05 mattproch

@mattproch please provide a sample project, the latest releases were never tested with react-native-map-clustering

salah-ghanim avatar May 13 '25 11:05 salah-ghanim

@salah-ghanim I'm also having the same issue on 1.23.8 but i'm not using react-native-map-clustering. From my tests the crash happens if i give the map +200 markers. This is the adb log if it can help:

05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: dispatchMountItems: caught exception, displaying mount state
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: java.lang.IndexOutOfBoundsException: Index: 235, Size: 225
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at java.util.ArrayList.add(ArrayList.java:483)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.rnmaps.maps.MapView.addFeature(MapView.java:1066)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.rnmaps.fabric.MapViewManager.addView(MapViewManager.java:325)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.rnmaps.fabric.MapViewManager.addView(MapViewManager.java:43)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.mounting.SurfaceMountingManager.addViewAt(SurfaceMountingManager.java:413)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.java:119)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.executeOrEnqueue(MountItemDispatcher.java:387)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.java:293)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.java:126)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.FabricUIManager$DispatchUIFrameCallback.doFrameGuarded(FabricUIManager.java:1394)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.fabric.GuardedFrameCallback.doFrame(GuardedFrameCallback.kt:22)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.modules.core.ReactChoreographer.frameCallback$lambda$1(ReactChoreographer.kt:60)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.modules.core.ReactChoreographer.$r8$lambda$nSkFhrr5T7rop_XKwzlLov4NLLw(Unknown Source:0)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.facebook.react.modules.core.ReactChoreographer$$ExternalSyntheticLambda0.doFrame(D8$$SyntheticClass:0)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1056)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.view.Choreographer.doCallbacks(Choreographer.java:880)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.view.Choreographer.doFrame(Choreographer.java:809)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1043)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.os.Handler.handleCallback(Handler.java:938)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.os.Looper.loop(Looper.java:236)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at android.app.ActivityThread.main(ActivityThread.java:7861)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at java.lang.reflect.Method.invoke(Native Method)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
05-16 16:08:12.707 12902 12902 E unknown:MountItemDispatcher: dispatchMountItems: mountItem: next mountItem triggered exception!

scottaglia avatar May 16 '25 14:05 scottaglia

Also running into this, only happens when I have around 60+ markers on the map.

ammar-madni avatar May 21 '25 01:05 ammar-madni

@mattproch @scottaglia If you could patch your react-native-maps code with the changes proposed in my PR and let us know whether the changes helped that would great. Thanks.

ammar-madni avatar May 21 '25 03:05 ammar-madni

@ammar-madni Thanks! I'll try the patch and post the result here after.

mattproch avatar May 21 '25 12:05 mattproch

@ammar-madni It doesn't crash but there is still a problem if you use clustering or change the number of markers. Some of them are not removed and live there as ghost markers.

mattproch avatar May 21 '25 13:05 mattproch

Thanks for testing @mattproch

I don't use clustering so I assume the crashing aspect has nothing to do with that. And I guess the fact that its not crashing anymore is a good sign?

Could you try without this bit in the removeFeatureAt method?

        // Guard against stale / out of range remove instructions which can be emitted when
        // views are deleted while touch events are still active or due to concurrent diffing
        // in the Fabric renderer.
        if (index < 0 || index >= features.size()) {
            return;
        }

I suspect thats the cause of the ghost markers - I've updated my PR accordingly.

ammar-madni avatar May 21 '25 15:05 ammar-madni

@ammar-madni crash is still happening but error changed. The app crashes when the screen that contains the map is unmounted

05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RCTView id=2024 parentTag=2028 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <CellContainer id=2028 parentTag=618 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RCTText id=2032 parentTag=2118 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RCTText id=2036 parentTag=2118 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RNSVGCircle id=2038 parentTag=2040 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RNSVGGroup id=2040 parentTag=null isRoot=false />
05-21 18:44:58.823 15202 15202 E unknown:SurfaceMountingManager: <RNSVGSvgViewAndroid id=2042 parentTag=2118 isRoot=false />
05-21 18:44:58.823 15202 15202 E unknown:SurfaceMountingManager: <RCTText id=2046 parentTag=2118 isRoot=false />
05-21 18:44:58.823 15202 15202 W unknown:BridgelessReact: ReactHost{0}.handleHostException(message = "Index: 277, Size: 0")
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: Exception in native call
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: java.lang.IndexOutOfBoundsException: Index: 277, Size: 0
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at java.util.ArrayList.get(ArrayList.java:437)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.rnmaps.maps.MapView.getFeatureAt(MapView.java:1158)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.rnmaps.fabric.MapViewManager.getChildAt(MapViewManager.java:78)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.rnmaps.fabric.MapViewManager.getChildAt(MapViewManager.java:43)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.SurfaceMountingManager.removeViewAt(SurfaceMountingManager.java:503)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.java:121)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.executeOrEnqueue(MountItemDispatcher.java:387)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.java:293)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.java:126)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.FabricUIManager$3.runGuarded(FabricUIManager.java:837)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:29)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.FabricUIManager.scheduleMountItem(FabricUIManager.java:841)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler.triggerUI(Native Method)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler.lambda$new$0(AndroidUIScheduler.java:28)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler.$r8$lambda$Owjjhl033zNSHsU6ZfWQNbZEGbI(Unknown Source:0)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler$1.runGuarded(AndroidUIScheduler.java:49)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:29)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.os.Handler.handleCallback(Handler.java:938)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.os.Looper.loop(Looper.java:236)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.app.ActivityThread.main(ActivityThread.java:7861)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at java.lang.reflect.Method.invoke(Native Method)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

scottaglia avatar May 21 '25 16:05 scottaglia

@ammar-madni crash is still happening but error changed. The app crashes when the screen that contains the map is unmounted

05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RCTView id=2024 parentTag=2028 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <CellContainer id=2028 parentTag=618 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RCTText id=2032 parentTag=2118 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RCTText id=2036 parentTag=2118 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RNSVGCircle id=2038 parentTag=2040 isRoot=false />
05-21 18:44:58.822 15202 15202 E unknown:SurfaceMountingManager: <RNSVGGroup id=2040 parentTag=null isRoot=false />
05-21 18:44:58.823 15202 15202 E unknown:SurfaceMountingManager: <RNSVGSvgViewAndroid id=2042 parentTag=2118 isRoot=false />
05-21 18:44:58.823 15202 15202 E unknown:SurfaceMountingManager: <RCTText id=2046 parentTag=2118 isRoot=false />
05-21 18:44:58.823 15202 15202 W unknown:BridgelessReact: ReactHost{0}.handleHostException(message = "Index: 277, Size: 0")
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: Exception in native call
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: java.lang.IndexOutOfBoundsException: Index: 277, Size: 0
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at java.util.ArrayList.get(ArrayList.java:437)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.rnmaps.maps.MapView.getFeatureAt(MapView.java:1158)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.rnmaps.fabric.MapViewManager.getChildAt(MapViewManager.java:78)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.rnmaps.fabric.MapViewManager.getChildAt(MapViewManager.java:43)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.SurfaceMountingManager.removeViewAt(SurfaceMountingManager.java:503)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.java:121)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.executeOrEnqueue(MountItemDispatcher.java:387)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.java:293)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.java:126)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.FabricUIManager$3.runGuarded(FabricUIManager.java:837)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:29)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.fabric.FabricUIManager.scheduleMountItem(FabricUIManager.java:841)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler.triggerUI(Native Method)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler.lambda$new$0(AndroidUIScheduler.java:28)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler.$r8$lambda$Owjjhl033zNSHsU6ZfWQNbZEGbI(Unknown Source:0)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.swmansion.worklets.AndroidUIScheduler$1.runGuarded(AndroidUIScheduler.java:49)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:29)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.os.Handler.handleCallback(Handler.java:938)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.os.Looper.loop(Looper.java:236)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at android.app.ActivityThread.main(ActivityThread.java:7861)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at java.lang.reflect.Method.invoke(Native Method)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
05-21 18:44:58.823 15202 15202 E unknown:ReactNative: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

@scottaglia Can you try clamping the index in the getFeatureAt method as below:

    public View getFeatureAt(int index) {
        // Clamp index to valid bounds to avoid IndexOutOfBoundsException.
        if (index < 0 || index >= features.size()) {
            return null;
        }
        return features.get(index);
    }

ammar-madni avatar May 21 '25 16:05 ammar-madni

@ammar-madni It Works!

scottaglia avatar May 21 '25 17:05 scottaglia

can anyone here please add a completely working sample

@ammar-madni thanks for the code but I really would love to understand the bug and make sure this is the correct way to fix it, there might be unexpected side effects for the change of index that you're doing.

salah-ghanim avatar Jun 08 '25 10:06 salah-ghanim

@salah-ghanim I updated to the latest version (1.24.1) just now and it seems I no longer need the fix.

ammar-madni avatar Jun 08 '25 15:06 ammar-madni

@salah-ghanim I updated to the latest version (1.24.1) just now and it seems I no longer need the fix.

Spoke too soon still crashes without the fixes.

ammar-madni avatar Jun 08 '25 15:06 ammar-madni

@ammar-madni please submit a full repo that reproduces this issue so that it can be analysed

salah-ghanim avatar Jun 09 '25 10:06 salah-ghanim

@salah-ghanim Sure,

I did find that the previous fix had some side affects like mixing up the markers so pressing one navigated to another.

For the time being I've found that conditionally rendering my map markers only when the map is ready and also artificially delaying my mapIsReady state with a set timeout of 1000ms in the onMapReady callback prevents this issue.

Just mentioning it here incase it's useful to everyone else experiencing these crashes on Android.

ammar-madni avatar Jun 09 '25 12:06 ammar-madni

@ammar-madni the map already delayes display of Markers until map is ready

https://github.com/react-native-maps/react-native-maps/blob/master/src/MapView.tsx

so it doesn't make too much sense to me

salah-ghanim avatar Jun 10 '25 08:06 salah-ghanim

@salah-ghanim Heres a repro, the data needs to be loaded from the cache.

https://github.com/ammar-madni/repro-index-out-of-bounds

ammar-madni avatar Jun 12 '25 12:06 ammar-madni

Here's another log of this happening on 1.24.3 if it helps...

RuntimeException: Exception thrown when executing UIFrameGuarded
    at com.facebook.react.fabric.FabricUIManager$DispatchUIFrameCallback.doFrameGuarded(FabricUIManager.java:1400)
    at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.kt:25)
    at com.facebook.react.modules.core.ReactChoreographer.frameCallback$lambda$1(ReactChoreographer.kt:59)
    at com.facebook.react.modules.core.ReactChoreographer.$r8$lambda$nSkFhrr5T7rop_XKwzlLov4NLLw
    at com.facebook.react.modules.core.ReactChoreographer$$ExternalSyntheticLambda0.doFrame(D8$$SyntheticClass:0)
...
(13 additional frame(s) were not displayed)

IllegalStateException: addViewAt: failed to insert view [2652] into parent [1822] at index 4
    at com.facebook.react.fabric.mounting.SurfaceMountingManager.addViewAt(SurfaceMountingManager.java:411)
    at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.execute(IntBufferBatchMountItem.java:141)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.executeOrEnqueue(MountItemDispatcher.java:370)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.java:265)
    at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.java:122)
...
(18 additional frame(s) were not displayed)

IndexOutOfBoundsException: Index: 4, Size: 1
    at java.util.ArrayList.add(ArrayList.java:483)
    at com.rnmaps.maps.MapView.addFeature(MapView.java:1092)
    at com.rnmaps.fabric.MapViewManager.addView(MapViewManager.java:325)
    at com.rnmaps.fabric.MapViewManager.addView(MapViewManager.java:43)
    at com.facebook.react.fabric.mounting.SurfaceMountingManager.addViewAt(SurfaceMountingManager.java:408)
...
(22 additional frame(s) were not displayed)

Still seeing a lot of this happening in production and no idea what to do about it :(

vonkanehoffen avatar Jun 23 '25 07:06 vonkanehoffen

@ammar-madni the map already delayes display of Markers until map is ready

https://github.com/react-native-maps/react-native-maps/blob/master/src/MapView.tsx

so it doesn't make too much sense to me

@salah-ghanim Any movement on this?

https://github.com/ammar-madni/repro-index-out-of-bounds

The repro above is pretty simple, when you first load the app the marker data is generated. The second time will be from the cache and thats what crashes the app with the index out of bounds exception.

Let me know if there is anything else I can do to help make this issue easier to debug and resolve.

ammar-madni avatar Jun 25 '25 15:06 ammar-madni

with this patch for 1.24.3, we protect the index and normally the crash you describe ;)

diff --git a/node_modules/react-native-maps/android/src/main/java/com/rnmaps/fabric/MapViewManager.java b/node_modules/react-native-maps/android/src/main/java/com/rnmaps/fabric/MapViewManager.java
index bd16ddd..eab8786 100644
--- a/node_modules/react-native-maps/android/src/main/java/com/rnmaps/fabric/MapViewManager.java
+++ b/node_modules/react-native-maps/android/src/main/java/com/rnmaps/fabric/MapViewManager.java
@@ -317,12 +317,14 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM

     @Override
     public void addView(MapView parent, View child, int index) {
-        if (child instanceof MapMarker && ((MapMarker) child).isLoadingImage()){
+        int safeIndex = Math.min(index, parent.getFeatureCount());
+
+        if (child instanceof MapMarker && ((MapMarker) child).isLoadingImage()) {
             ((MapMarker) child).setImageLoadedListener((uri, drawable, b) -> {
                 parent.addFeature(child, parent.getFeatureCount());
             });
         } else {
-            parent.addFeature(child, index);
+            parent.addFeature(child, safeIndex);
         }
     }

rocket13011 avatar Jul 04 '25 16:07 rocket13011

fixed in v1.24.15

salah-ghanim avatar Aug 02 '25 14:08 salah-ghanim