Skip to content

Crash: superCluster.getClusters receives NaN zoom from returnMapZoom #294

Description

@hamzawaleed01

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:

  1. calculateBBox() produces [NaN, NaN, NaN, NaN]
  2. GeoViewport.viewport() (from @mapbox/geo-viewport) computes pixel positions from NaN bounds — all intermediate values become NaN
  3. 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
  4. superCluster.getClusters(bBox, NaN) throws

Steps to Reproduce

  1. Use ClusteredMapView with markers
  2. Rapidly zoom/pan the map, or observe during map initialization
  3. The native map emits a region with undefined/NaN delta values
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions