From 59e4c757b6d60ca3b8c256f6fb461b9afeea2b8b Mon Sep 17 00:00:00 2001 From: HF Date: Sat, 30 May 2020 18:52:30 +0200 Subject: [PATCH] better chunk error handling if redis data is invalid for whatever reason --- src/core/Image.js | 6 +++--- src/core/Tile.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/Image.js b/src/core/Image.js index 72951aa..5c81609 100644 --- a/src/core/Image.js +++ b/src/core/Image.js @@ -53,7 +53,7 @@ export async function imageABGR2Canvas( for (let cx = ucx; cx <= lcx; cx += 1) { for (let cy = ucy; cy <= lcy; cy += 1) { chunk = await RedisCanvas.getChunk(canvasId, cx, cy); - chunk = (chunk) + chunk = (chunk && chunk.length === TILE_SIZE * TILE_SIZE) ? new Uint8Array(chunk) : new Uint8Array(TILE_SIZE * TILE_SIZE); // offset of chunk in image @@ -130,7 +130,7 @@ export async function imagemask2Canvas( for (let cx = ucx; cx <= lcx; cx += 1) { for (let cy = ucy; cy <= lcy; cy += 1) { chunk = await RedisCanvas.getChunk(canvasId, cx, cy); - chunk = (chunk) + chunk = (chunk && chunk.length === TILE_SIZE * TILE_SIZE) ? new Uint8Array(chunk) : new Uint8Array(TILE_SIZE * TILE_SIZE); // offset of chunk in image @@ -201,7 +201,7 @@ export async function protectCanvasArea( for (let cx = ucx; cx <= lcx; cx += 1) { for (let cy = ucy; cy <= lcy; cy += 1) { chunk = await RedisCanvas.getChunk(canvasId, cx, cy); - if (!chunk) { + if (!chunk || chunk.length !== TILE_SIZE * TILE_SIZE) { continue; } chunk = new Uint8Array(chunk); diff --git a/src/core/Tile.js b/src/core/Tile.js index eed41f1..939d034 100644 --- a/src/core/Tile.js +++ b/src/core/Tile.js @@ -143,7 +143,7 @@ export async function createZoomTileFromChunk( for (let dy = 0; dy < TILE_ZOOM_LEVEL; dy += 1) { for (let dx = 0; dx < TILE_ZOOM_LEVEL; dx += 1) { chunk = await redisCanvas.getChunk(canvasId, xabs + dx, yabs + dy); - if (!chunk) { + if (!chunk || chunk.length !== TILE_SIZE * TILE_SIZE) { na.push([dx, dy]); continue; } @@ -313,7 +313,7 @@ export async function createTexture( for (let dy = 0; dy < amount; dy += 1) { for (let dx = 0; dx < amount; dx += 1) { chunk = await redisCanvas.getChunk(canvasId, dx, dy); - if (!chunk) { + if (!chunk || chunk.length !== TILE_SIZE * TILE_SIZE) { na.push([dx, dy]); continue; }