From d01e2faa756160033f34f4b8cafb30f464afb75a Mon Sep 17 00:00:00 2001 From: GoteGuru Date: Fri, 20 May 2022 01:15:03 +0200 Subject: [PATCH] Reuse existing image element on conversion. --- modules/ui/heightmap-editor.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js index fae944f3..2630658c 100644 --- a/modules/ui/heightmap-editor.js +++ b/modules/ui/heightmap-editor.js @@ -1006,10 +1006,14 @@ function editHeightmap() { this.value = ""; // reset input value to get triggered if the file is re-uploaded const reader = new FileReader(); - const img = new Image(); - img.id = "imageToConvert"; - img.style.display = "none"; - document.body.appendChild(img); + const imgId = "imageToConvert"; + let img = document.getElementById(imgId); + if (!img) { + img = new Image(); + img.id = imgId; + img.style.display = "none"; + document.body.appendChild(img); + } img.onload = function () { const ctx = document.getElementById("canvas").getContext("2d");