From 078b83633fbc6e8fdf004503287b4c4dc5e77c20 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 1 Aug 2021 13:31:54 +0300 Subject: [PATCH] fix: add rivers when rivers array is empty --- modules/ui/rivers-creator.js | 2 +- modules/ui/tools.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ui/rivers-creator.js b/modules/ui/rivers-creator.js index 22f88b70..0a2d62c6 100644 --- a/modules/ui/rivers-creator.js +++ b/modules/ui/rivers-creator.js @@ -79,7 +79,7 @@ function createRiver() { const riverCells = createRiver.cells; if (riverCells.length < 2) return tip("Add at least 2 cells", false, "error"); - const riverId = last(rivers).i + 1; + const riverId = rivers.length ? last(rivers).i + 1 : 1; const parent = cells.r[last(riverCells)] || riverId; riverCells.forEach(cell => { diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 5243cd95..8783fded 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -539,7 +539,7 @@ function addRiverOnClick() { const {alterHeights, resolveDepressions, addMeandering, getRiverPath, getBasin, getName, getType, getWidth, getOffset, getApproximateLength} = Rivers; const riverCells = []; - let riverId = last(rivers).i + 1; + let riverId = rivers.length ? last(rivers).i + 1 : 1; let parent = riverId; const initialFlux = grid.cells.prec[cells.g[i]];