diff --git a/src/layers/weather/rasterTiles.js b/src/layers/weather/rasterTiles.js index 50ef49a05..2536f2e25 100644 --- a/src/layers/weather/rasterTiles.js +++ b/src/layers/weather/rasterTiles.js @@ -86,7 +86,11 @@ export function createFrameTileFetch({ }); if (pixels === null) { both?.throwIfAborted(); - empty ??= canvasBytes(canvas()); + // A failed encode is not kept: the next empty tile tries again. + empty ??= canvasBytes(canvas()).catch((error) => { + empty = null; + throw error; + }); return { bytes: (await empty).slice(0), contentType: 'image/png' }; } let tileCanvas; diff --git a/src/layers/weather/rasterTiles.test.mjs b/src/layers/weather/rasterTiles.test.mjs index 8b383fe2f..dcfb4b7a4 100644 --- a/src/layers/weather/rasterTiles.test.mjs +++ b/src/layers/weather/rasterTiles.test.mjs @@ -198,6 +198,23 @@ test('a null tile is one shared transparent tile, drawn rather than missing', as assert.equal(canvases[0].encoded, 1); }); +test('an empty tile that failed to encode is encoded again next time', async () => { + const { ask, canvases } = frameFetch(async () => null, { + createCanvas: () => { + const canvas = tileCanvas(); + if (!canvases.length) + canvas.convertToBlob = async () => + Promise.reject(new Error('no encoder')); + canvases.push(canvas); + return canvas; + }, + }); + await assert.rejects(ask(0, 0, 0), /no encoder/); + const next = await ask(1, 0, 0); + assert.equal(text(next.bytes), 'tile:0'); + assert.equal(canvases.length, 2); +}); + test('a failed tile rejects, which the renderer reports as a tile error', async () => { const { ask } = frameFetch(async () => { throw new Error('frame unavailable');