mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.14k stars 2.21k forks source link

.loseContext() / .restoreContext() breaks the map (WEBGL_lose_context) #9516

Open sfahnens opened 4 years ago

sfahnens commented 4 years ago

mapbox-gl-js version: 1.9.1 / latest release (or whatever the examples page uses.)

browsers:

Steps to Trigger Behavior / Link to Demonstration

  1. Go to the demo page: https://docs.mapbox.com/mapbox-gl-js/example/simple-map/
  2. Open developer tools and ensure that the iframe with the map is active.
  3. var ext = document.querySelector('#map canvas').getContext('webgl').getExtension('WEBGL_lose_context')
  4. ext.loseContext()
  5. ext.restoreContext()

Expected Behavior

Map view goes blank on .loseContext() and comes back on .restoreContext().

Actual Behavior

Map view goes blank but does not come back. Instead many WebGL errors appear on the console:

WebGL: INVALID_OPERATION: bindBuffer: object does not belong to this context value.js:403 WebGL: INVALID_OPERATION: bindBuffer: object does not belong to this context value.js:416 WebGL: INVALID_OPERATION: bindTexture: object does not belong to this context line_atlas.js:200 WebGL: INVALID_OPERATION: bindTexture: object does not belong to this context texture.js:92

Notes

I discovered the problem while experimenting with a custom layer. Our stuff came right back after handling the appropriate events ("webglcontextlost" and "webglcontextrestored"). Otherwise, similar bindBuffer errors occur. After some panning and zooming around it looks like the map (line and symbols layers) works everywhere, but in area/zoom that were active when lose/restore happened.

For the example map only the symbol layers seems to work elsewhere?!

I'm not really sure if this is a real problem, or occurs only with the extension. However I'm not aware of another possibility to trigger context loss for debugging purposes, so it would be nice if this works :)

rudyhadoux commented 3 years ago

Same problem within an Angular Web App. Is it possible please to add an automatic ext.restoreContext() in your next version ?

wawa2016 commented 2 years ago

I got the same issue. Is there a solution to this problem?

rudyhadoux commented 2 years ago

My solution is to use Leaflet, Google Maps or AWS Location Services.

Coldsewoo commented 2 years ago

Any updates?

jasonHav commented 2 years ago

Also running into this issue - would be really interested in hearing from anyone who's been able to handle context loss in mapbox-gl

zipporaSay commented 1 year ago

any updates?

Ysrbolles commented 1 year ago

I got the same issue. Is there a solution to this problem?

lisitso commented 1 year ago

Hi, any update?

Ysrbolles commented 1 year ago

Hi, any update?

Check if you are using another package that uses WebGL

ncnthien commented 1 day ago

it's 2024 now, any updates?