TerrainModify.UpdateArea IndexOutOfRangeException: Array index is out of range
I have been updating the terrain in the Cities: Skyline map editor with a mod. If I keep the update area small enough than there is no issue. However when I select a larger area and update the values for height in the array that I am getting a error from outside my code during the Terrain.UpdateArea call. So my code loops trough the height array and updates the height if the coordinates fall into my selected area. then I send update area call which uses the array internally and updates the map. This all is working however I am getting random errors like the one shown below, see the code snippet below to error for additional details. Source code: https://github.com/RickDeschenes/AnotherTerrianTool Error Log details: IndexOutOfRangeException: Array index is out of range. at TerrainModify.UpdateAreaImplementation () [0x00000] in :0 at TerrainModify.UpdateArea (Int32 minX, Int32 minZ, Int32 maxX, Int32 maxZ, Boolean heights, Boolean surface, Boolean zones) [0x00000] in :0 at AnotherTerrain.AnotherTerrainTool.ApplyUndo () [0x00000] in :0 at AnotherTerrain.AnotherTerrainTool.OnToolGUI (UnityEngine.Event e) [0x00000] in :0 at ToolBase.OnGUI () [0x00000] in :0 (Filename: Line: -1) Simulation error: Array index is out of range. at TerrainModify.UpdateAreaImplementation () [0x00000] in :0 at TerrainModify.EndUpdateArea () [0x00000] in :0 at SimulationManager.SimulationStep () [0x00000] in :0 at SimulationManager.SimulationThread () [0x00000] in :0 [Core] Code private array instance
readonly ushort[] m_rawHeights = Singleton<TerrainManager>.instance.RawHeights;
//validate the size of the array
m_maxArea = m_rawHeights.Length;
//1168561 is 1080x1080 the map area
for (int i = minZ; i <= maxZ; i++)
{
for (int j = minX; j <= maxX; j++)
{
int num = i * 1081 + j;
//We want the new height in the new/raw
m_rawHeights[num] = finalHeight;
}
}
//TerrainModify.UpdateArea(minX - 1, minZ - 1, maxX + 1, maxZ + 1, true, false, false);
//we need to update the area in 120 point sections
for (int i = minZ; i <= maxZ; i++)
{
for (int j = minX; j <= maxX; j++)
{
TerrainModify.UpdateArea(j, i, Math.Max(j + 120, maxZ), Math.Max(i + 120, maxX), true, true, false);
//log = j + ", " + i + ":" + Math.Max(j + 120, maxZ) + ", " + Math.Max(i + 120, maxX);
//LoadingExtension.WriteLog("Processing: " + log);
j += 119;
}
i += 119;
}
The code updates the map but I get the out of range error. I wrapped these calls in try catch but nothing was trapped so I have to assume this is being trapped internal to the game itself. the thing is the error only shows Details No Details: I found the log by searching the hard drive.
Your answer
![](https://koobas.hobune.stream/wayback/20220612074321im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Argument out of range - 2 year old project 1 Answer
canseetarget how to? 0 Answers
EnemyAI code help 0 Answers
Asset Null Exception - No assetGUID 0 Answers