Skip to content
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

Allow Safari to use the Image API to decode images to avoid a potential crash #11510

Closed

Conversation

ryanhamley
Copy link
Contributor

@ryanhamley ryanhamley commented Feb 15, 2022

Launch Checklist

  • briefly describe the changes in this PR
    • This reverts part of the change in Always retain raster tile cache control data #10494 and only uses window.createImageBitmap to decode images when offscreenCanvas is supported. OffscreenCanvas is not supported by Safari which forces Safari to decode images using the Image API. Certain types of WebP images (raster-dem tiles over the ocean with small or no variation in them) cause Safari 15.2 and Safari 15.3 to crash when decoded with createImageBitmap. With the Image API, these images still fail to decode, but Safari properly handles the error so the failure is harmless.
    • The upside of this change is that we can continue requesting WebP images which are significantly smaller than PNG images but we avoid the Safari tab crashing.
    • The original bug for the Safari crash is 3d terrain crashes Safari 15.3 #11494
    • The offscreenCanvasSupported() check was first added in ImageBitmap and OffscreenCanvas for DEM tiles #8845 as a progressive enhancement.
  • manually test the debug page
    • Without this change, Safari 15.2/15.3 consistently crashes with certain tiles. With this change, Safari gracefully handles the bug by logging an error.
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Allow Safari to use the Image API to decode images to avoid a potential crash</changelog>

This is a public style and location I used to manually test this.

var map = window.map = new mapboxgl.Map({
    container: 'map',
    zoom: 14.14,
    center: [-118.39997, 33.75873],
    style: 'mapbox://styles/ryanhamley/ckzhfiobs001i16kdrvuo8isv',
    hash: true
});

@ryanhamley
Copy link
Contributor Author

@mourner I changed this to check for Safari so that Firefox can still use createImageBitmap and get the benefits of that. Can you re-review?

@ryanhamley ryanhamley changed the title Only use createImageBitmap to decode images when offscreenCanvas is supported Allow Safari to use the Image API to decode images to avoid a potential crash Feb 15, 2022
if (window.createImageBitmap) {
// force Safari to use the Image API to avoid a potential crash
// See https://github.com/mapbox/mapbox-gl-js/issues/11494
if (!isSafari(window) && window.createImageBitmap) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for this type of check to be more granular and check for version number in the user agent?
e.g. isSafari(window, '15.3')). If this is fixed in 15.4, maybe it wouldn't make sense to prevent this code path for all future Safari versions, so users can still benefit from #10491.

@ryanhamley
Copy link
Contributor Author

Closing since this issue was fixed on the server-side

@ryanhamley ryanhamley closed this Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants