Fix crash when returnMapZoom returns NaN or Infinity#295
Open
hamzawaleed01 wants to merge 1 commit into
Open
Conversation
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], which flows into GeoViewport.viewport(). The Math.max/Math.min clamping in geo-viewport does not catch NaN (Math.min(20, NaN) = NaN), so superCluster.getClusters(bBox, NaN) throws an exception. This commit adds a guard to check that zoom is finite before calling getClusters, returning an empty markers array (or early-returning from the region change handler) when zoom is invalid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #294
superCluster.getClusters(bBox, zoom)crashes whenreturnMapZoom()returnsNaNorInfinity. This happens because the native map can emit regions withNaN/undefinedvalues during initialization or rapid zoom/pan, and@mapbox/geo-viewport'sMath.max/Math.minclamping does not catchNaN.Related Issues
This fix likely resolves or mitigates several open crash reports that share the same root cause — invalid region values propagating into supercluster:
l.rangeis the internal supercluster tree lookup that fails when given NaN zoomcalculateBBox→ NaN propagationAll of these trace back to the same missing validation:
returnMapZoom()can returnNaN/Infinity, and the library passes it directly tosuperCluster.getClusters()without checking.Changes
Added a guard in
ClusteredMapView.jsto check thatzoomis finite before callinggetClusters():_onRegionChangeComplete(line ~137): early-returns and still fires theonRegionChangeCompletecallbackWhy this is the right fix
@mapbox/geo-viewportnot clampingNaN, but that's an upstream dependency we can't control heregetClusterscall site is minimal, non-breaking, and handles all edge cases