Fix crash when a symbol layer without feature-state paint gets a pain… - #13721
Open
liueric-dev wants to merge 2 commits into
Open
Fix crash when a symbol layer without feature-state paint gets a pain…#13721liueric-dev wants to merge 2 commits into
liueric-dev wants to merge 2 commits into
Conversation
…t update Tile#updateBuckets picks bucket.stateDependentLayers whenever withStateUpdates is true, but enters the update block under separately-checked conditions (hasPaintUpdate, needsSymbolUBOUpdate). If a source carries feature state but none of a bucket's layers actually read it in their paint (isStateDependent), stateDependentLayers is empty, so a concurrent paint-property change (e.g. setFeatureState followed by setPaintProperty) passes an empty layers array into SymbolBucket#update. Its UBO-based update path unconditionally casts layers[0] to SymbolStyleLayer and dereferences .paint, throwing when the array is empty. Factor the repeated withStateUpdates && stateDependentLayers.length !== 0 check into one hasStateDependentLayers value, reused for both the layers selection and all three guards that depend on it, so the array chosen can never disagree with the condition that lets it be used. Fixes mapbox#13714 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
|
|
Hey, @liueric-dev 👋 Thanks for your contribution to Mapbox GL JS! Important: This repository does not accept direct merges. All changes go through our internal review process. What happens next:
Please respond to any review comments on this PR. For more details, see CONTRIBUTING.md. |
The invariant it described belongs in the PR description, not the code — it referenced the fix history rather than a non-obvious runtime constraint. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Fix crash when a symbol layer without feature-state paint gets a paint update
What changed
Tile#updateBucketsselectedbucket.stateDependentLayerswheneverwithStateUpdateswas true, but the guard that decides whether to use that array checked a wider, independently-satisfiable set of conditions (hasPaintUpdate,needsSymbolUBOUpdate). When a source carries state but none of a symbol bucket's layers actually read it in their paint,stateDependentLayersis empty, but the block can possibly still run because of an unrelated paint-property change. That passes an emptylayersarray itoSymbolBucket#update, whose UBO-based update path unconditionally doeslayers[0] as SymbolStyleLayerand dereferences.paint, throwingTypeError: Cannot read properties of undefined (reading 'paint').Fixed by factoring the check into one
hasStateDependentLayersvalue and reusing it everywherestateDependentLayersis consulted, so the array that gets used and the condition that permits using it can never disagree.Why this contribution
This is a real, currently-open, unclaimed bug report (#13714, labeled
bug) with a clear, minimal repro: callingsetFeatureStatefollowed bysetPaintPropertyon a symbol layer with no["feature-state", ...]expression in its paint crashes the map. I verified the other bucket types (fill/line/circle/fill-extrusion) aren't affected — onlySymbolBuckethas a UBO-binder path that indexeslayers[0]unconditionally; the others iterate the array safely.What problem it solves
Prevents an uncaught exception that breaks rendering entirely for any map that sets feature state on a source shared with a symbol layer that doesn't itself use feature-state in its paint — a fairly common pattern (e.g. a line layer using hover state, symbol layer on the same source not using it).
Testing
test/unit/source/tile.test.tsregression test: constructs aTile+SymbolBucketwith no state-dependent paint, callsupdateBuckets()with feature state + a paint update, asserts it doesn't throw. Confirmed it fails without the fix and passes with it.npm run tsc,npm run lint, and the fulltile.test.tssuite all pass with no regressions.setFeatureState+setPaintPropertysequence from the issue.Fixes #13714
Launch Checklist
@mapbox/map-design-team@mapbox/static-apisif this PR includes style spec API or visual changes.@mapbox/gl-nativeif this PR includes shader changes or needs a native port.@mapbox/gl-nativeif this PR disables any test because it also needs to be disabled on their side.gl-nativeto groom in the MAPSNAT JIRA queue if this PR includes shader changes or features not present in the native side or if it disables a test that's not disabled there.