issue-277 few null checks to avoid crash when node went under bottom of screen

This commit is contained in:
Daniel Lazar
2019-08-07 08:52:58 +02:00
parent 96655baff2
commit 16033a658c

View File

@ -59,14 +59,22 @@ export default class PathFinding {
pathToStart: number[][];
pathToEnd: number[][];
} {
const startIndex = path.findIndex(point => matrix[point[1]][point[0]] === 0);
const startIndex = path.findIndex(point => {
if (matrix[point[1]])
return matrix[point[1]][point[0]] === 0;
else return false;
});
const endIndex =
path.length -
1 -
path
.slice()
.reverse()
.findIndex(point => matrix[point[1]][point[0]] === 0);
.findIndex(point => {
if (matrix[point[1]])
return matrix[point[1]][point[0]] === 0;
else return false;
});
// are we trying to create a path exclusively through blocked areas?
// if so, let's fallback to the linear routing