Description
superCluster.getClusters(bBox, zoom) crashes when returnMapZoom() returns NaN or Infinity.
Root Cause
The native map can emit regions with NaN or undefined values for latitude, longitude, latitudeDelta, or longitudeDelta during initialization or rapid zoom/pan transitions. When this happens:
calculateBBox() produces [NaN, NaN, NaN, NaN]
GeoViewport.viewport() (from @mapbox/geo-viewport) computes pixel positions from NaN bounds — all intermediate values become NaN
- The
Math.max(minzoom, Math.min(maxzoom, adjusted)) clamp in geo-viewport does not catch NaN because Math.min(20, NaN) evaluates to NaN and Math.max(0, NaN) evaluates to NaN
superCluster.getClusters(bBox, NaN) throws
Steps to Reproduce
- Use
ClusteredMapView with markers
- Rapidly zoom/pan the map, or observe during map initialization
- The native map emits a region with undefined/NaN delta values
- App crashes with an exception from supercluster
Proposed Fix
Guard zoom for null / non-finite values before calling getClusters() in both call sites in ClusteredMapView.js:
- Initial clustering (after
superCluster.load): return empty markers array if zoom is invalid
_onRegionChangeComplete: early-return and still call onRegionChangeComplete callback
See PR #TBD.
Environment
- react-native-map-clustering: 4.0.0
- react-native-maps: latest
- Platform: iOS & Android
Description
superCluster.getClusters(bBox, zoom)crashes whenreturnMapZoom()returnsNaNorInfinity.Root Cause
The native map can emit regions with
NaNorundefinedvalues forlatitude,longitude,latitudeDelta, orlongitudeDeltaduring initialization or rapid zoom/pan transitions. When this happens:calculateBBox()produces[NaN, NaN, NaN, NaN]GeoViewport.viewport()(from@mapbox/geo-viewport) computes pixel positions from NaN bounds — all intermediate values become NaNMath.max(minzoom, Math.min(maxzoom, adjusted))clamp in geo-viewport does not catch NaN becauseMath.min(20, NaN)evaluates toNaNandMath.max(0, NaN)evaluates toNaNsuperCluster.getClusters(bBox, NaN)throwsSteps to Reproduce
ClusteredMapViewwith markersProposed Fix
Guard
zoomfornull/ non-finite values before callinggetClusters()in both call sites inClusteredMapView.js:superCluster.load): return empty markers array if zoom is invalid_onRegionChangeComplete: early-return and still callonRegionChangeCompletecallbackSee PR #TBD.
Environment