diff --git a/src/client/graphics/layers/UnitLayer.ts b/src/client/graphics/layers/UnitLayer.ts index 5cae90c36..3e59dc7ba 100644 --- a/src/client/graphics/layers/UnitLayer.ts +++ b/src/client/graphics/layers/UnitLayer.ts @@ -82,6 +82,10 @@ export class UnitLayer implements Layer { * @returns Array of player's warships in range, sorted by distance (closest first) */ private findWarshipsNearCell(cell: { x: number; y: number }): UnitView[] { + if (!this.game.isValidCoord(cell.x, cell.y)) { + // The cell coordinate were invalid (user probably clicked outside the map), therefore no warships can be found + return []; + } const clickRef = this.game.ref(cell.x, cell.y); // Make sure we have the current player