-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
removeFeatureState crashes map if feature state isn't set on the feature at least once #9461
Comments
Did this just start with 1.9.0? I don't see any changes to the offending file that would have caused this. |
Nope, this has been around since at least 1.8 (and probably as long as we've had In case you can't load the glitch project (I'm having trouble today), reproducing js code is in the details (GitHub doesn't like showing all the html elements as text, so I left out the accompanying html): var map = new mapboxgl.Map({ container: 'map', // container id style: 'mapbox://styles/mapbox/streets-v11', center: [-74.5, 40], // starting position [lng, lat] zoom: 9 // starting zoom }); |
I encounter this bug in a similar context:
The result is the same error as as with the process of @sansumbrella The remove and re-add is very common in our setup as we have layers that depend on a constantly changing vector tile source. As there is no way to update a vector source we always have to remove all layers, remove the source, add the source again and then add the layers again. The error can be prevented by removing all feature state from the features of the source before removing it. I wonder if it would make sense to include this behavior in mapbox-gl (check and remove all feature state when |
@ryanhamley this bug is also affecting me... The map becomes unresponsive and then I get the same stack trace as detailed above on every attempted render (every time mouse moves, scrolls, etc.), while the map is frozen. Mapbox version 2.6.1 NOTE: the error does not occur for me during the |
same on 2.12.0 example
|
This is fixed in #12497 |
@kalimar and I discovered this bug while working with a community partner adding hover-based styling of country outlines.
For that application, we call
removeFeatureState
in response to mouse events on the map, which occasionally caused the crash described below. This crash affects anyone usingremoveFeatureState
, especially if they are doing so in response to user interactions where a correspondingsetFeatureState
may not have been processed.mapbox-gl-js version: 1.9.0, 1.8.0, 1.8.1
browser: Chrome, Firefox
Steps to Trigger Behavior
removeFeatureState
Note that we never called
setFeatureState
in the sequence above.Link to Demonstration
https://glitch.com/edit/#!/mbx-bug-report-remove-feature-state
https://mbx-bug-report-remove-feature-state.glitch.me/
Expected Behavior
The map continues to function. Since there was no feature state to remove, it continues about its business rendering existing features.
Actual Behavior
The map crashes and ceases to be interactive.
In Chrome, this message is printed to the console on every render attempt after the removeFeatureState call:
In Firefox, a slightly more helpful error is printed to the console:
Suggested fix
Add a test that confirms you can call
removeFeatureState
without crashing if the feature state hasn't been set.Add a check that the feature being modified exists before modifying it in source_state:
Workaround for users experiencing this issue
If you need to call
removeFeatureState
today, I recommend using a "safe" wrapper around it. For example, to remove a single feature state:The text was updated successfully, but these errors were encountered: