From db9a77fb259f4f2699b7edd18014589dcf9e5550 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 20 Jun 2017 21:19:04 +0300 Subject: [PATCH] Fix for IndexOutOfRange exceptions during map generation caused by very large wall cells near the entrance of the level (example seed: i1qecA7V) --- Barotrauma/Source/Map/Levels/CaveGenerator.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Barotrauma/Source/Map/Levels/CaveGenerator.cs b/Barotrauma/Source/Map/Levels/CaveGenerator.cs index 542ba571c..7941b69a7 100644 --- a/Barotrauma/Source/Map/Levels/CaveGenerator.cs +++ b/Barotrauma/Source/Map/Levels/CaveGenerator.cs @@ -257,8 +257,20 @@ namespace Barotrauma var targetCells = new List(); for (int i = 0; i < pathNodes.Count; i++) { - int cellIndex = FindCellIndex(pathNodes[i], cells, cellGrid, gridCellSize, 2, gridOffset); - targetCells.Add(cells[cellIndex]); + //a search depth of 2 is large enough to find a cell in almost all maps, but in case it fails, we increase the depth + int searchDepth = 2; + while (searchDepth < 5) + { + int cellIndex = FindCellIndex(pathNodes[i], cells, cellGrid, gridCellSize, searchDepth, gridOffset); + if (cellIndex > -1) + { + targetCells.Add(cells[cellIndex]); + break; + } + + searchDepth++; + } + } return GeneratePath(targetCells, cells, cellGrid, gridCellSize, limits, wanderAmount, mirror);