From 81c1ba2963bda4a030c62ba57d0c86a9a916511a Mon Sep 17 00:00:00 2001 From: Marc Emmanuel Date: Thu, 22 Jan 2026 18:28:09 +0100 Subject: [PATCH] fix: initialize heights array if not already set in HeightmapGenerator (#1277) --- src/modules/heightmap-generator.ts | 4 +--- src/utils/stringUtils.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/heightmap-generator.ts b/src/modules/heightmap-generator.ts index eb48f9f4..27fb063b 100644 --- a/src/modules/heightmap-generator.ts +++ b/src/modules/heightmap-generator.ts @@ -560,9 +560,7 @@ class HeightmapGenerator { if(!ctx) { throw new Error("Could not get canvas context"); } - if(!this.heights) { - throw new Error("Heights array is not initialized"); - } + this.heights = this.heights || new Uint8Array(cellsX * cellsY); ctx.drawImage(img, 0, 0, cellsX, cellsY); const imageData = ctx.getImageData(0, 0, cellsX, cellsY); this.setGraph(graph); diff --git a/src/utils/stringUtils.ts b/src/utils/stringUtils.ts index 02c4d42a..dc00a23a 100644 --- a/src/utils/stringUtils.ts +++ b/src/utils/stringUtils.ts @@ -6,7 +6,7 @@ import { rn } from "./numberUtils"; * @param {number} decimals - Number of decimal places (default is 1) * @returns {string} - The string with rounded numbers */ -export const round = (inputString: string, decimals: number = 1) => { +export const round = (inputString: string = "", decimals: number = 1) => { return inputString.replace(/[\d\.-][\d\.e-]*/g, (n: string) => { return rn(parseFloat(n), decimals).toString(); });