From 2311bf2b5b533c62784fa6aa90f271968bfa8df7 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Sun, 10 Jan 2021 12:42:05 +1100 Subject: [PATCH] Update MapToken.js --- src/components/map/MapToken.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/map/MapToken.js b/src/components/map/MapToken.js index f457c7c..995edf0 100644 --- a/src/components/map/MapToken.js +++ b/src/components/map/MapToken.js @@ -183,15 +183,14 @@ function MapToken({ const imageRef = useRef(); useEffect(() => { const image = imageRef.current; + if (!image) { + return; + } + const canvas = image.getCanvas(); const pixelRatio = canvas.pixelRatio || 1; - if ( - image && - tokenSourceStatus === "loaded" && - tokenWidth > 0 && - tokenHeight > 0 - ) { + if (tokenSourceStatus === "loaded" && tokenWidth > 0 && tokenHeight > 0) { const maxImageSize = token ? Math.max(token.width, token.height) : 512; // Default to 512px const maxTokenSize = Math.max(tokenWidth, tokenHeight); // Constrain image buffer to original image size