Skip to content

Commit

Permalink
fix ImageSource not working in FF/Safari (#10230)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner authored and ryanhamley committed Feb 17, 2021
1 parent f87090b commit 0f57807
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ function arrayBufferToImage(data: ArrayBuffer, callback: (err: ?Error, image: ?H
img.onload = () => {
callback(null, img);
URL.revokeObjectURL(img.src);
// prevent image dataURI memory leak in Safari
// prevent image dataURI memory leak in Safari;
// but don't free the image immediately because it might be uploaded in the next frame
// https://github.com/mapbox/mapbox-gl-js/issues/10226
img.onload = null;
img.src = transparentPngUrl;
window.requestAnimationFrame(() => { img.src = transparentPngUrl; });
};
img.onerror = () => callback(new Error('Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.'));
const blob: Blob = new window.Blob([new Uint8Array(data)], {type: 'image/png'});
Expand Down

0 comments on commit 0f57807

Please sign in to comment.