From b1d33155c67e7a3c1b2c393bc69f19f776ec6214 Mon Sep 17 00:00:00 2001 From: Rampastring Date: Tue, 12 Mar 2024 23:06:59 +0200 Subject: [PATCH] Fix crashes if a terrain generator preset contains too many entries for smudges, terrain objects or tiles --- .../TerrainGenerator/TerrainGeneratorSmudgeGroupsPanel.cs | 6 +++--- .../TerrainGeneratorTerrainTypeGroupsPanel.cs | 6 +++--- .../TerrainGenerator/TerrainGeneratorTileGroupsPanel.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorSmudgeGroupsPanel.cs b/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorSmudgeGroupsPanel.cs index b505f685..e0073fac 100644 --- a/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorSmudgeGroupsPanel.cs +++ b/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorSmudgeGroupsPanel.cs @@ -15,6 +15,8 @@ namespace TSMapEditor.UI.Windows.TerrainGenerator /// public class TerrainGeneratorSmudgeGroupsPanel : EditorPanel { + private const int MaxSmudgeTypeGroupCount = 8; + public TerrainGeneratorSmudgeGroupsPanel(WindowManager windowManager, Map map) : base(windowManager) { this.map = map; @@ -28,8 +30,6 @@ public TerrainGeneratorSmudgeGroupsPanel(WindowManager windowManager, Map map) : public override void Initialize() { - const int MaxSmudgeTypeGroupCount = 8; - smudgeTypeTextBoxes = new EditorTextBox[MaxSmudgeTypeGroupCount]; smudgeTypeOpenChances = new EditorNumberTextBox[MaxSmudgeTypeGroupCount]; smudgeTypeOccupiedChances = new EditorNumberTextBox[MaxSmudgeTypeGroupCount]; @@ -128,7 +128,7 @@ public List GetSmudgeGroups() public void LoadConfig(TerrainGeneratorConfiguration configuration) { - for (int i = 0; i < configuration.SmudgeGroups.Count; i++) + for (int i = 0; i < configuration.SmudgeGroups.Count && i < MaxSmudgeTypeGroupCount; i++) { var smudgeGroup = configuration.SmudgeGroups[i]; diff --git a/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTerrainTypeGroupsPanel.cs b/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTerrainTypeGroupsPanel.cs index 5b319b19..2f270692 100644 --- a/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTerrainTypeGroupsPanel.cs +++ b/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTerrainTypeGroupsPanel.cs @@ -15,6 +15,8 @@ namespace TSMapEditor.UI.Windows.TerrainGenerator /// public class TerrainGeneratorTerrainTypeGroupsPanel : EditorPanel { + private const int MaxTerrainTypeGroupCount = 8; + public TerrainGeneratorTerrainTypeGroupsPanel(WindowManager windowManager, Map map) : base(windowManager) { this.map = map; @@ -28,8 +30,6 @@ public TerrainGeneratorTerrainTypeGroupsPanel(WindowManager windowManager, Map m public override void Initialize() { - const int MaxTerrainTypeGroupCount = 8; - terrainTypeTextBoxes = new EditorTextBox[MaxTerrainTypeGroupCount]; terrainTypeOpenChances = new EditorNumberTextBox[MaxTerrainTypeGroupCount]; terrainTypeOccupiedChances = new EditorNumberTextBox[MaxTerrainTypeGroupCount]; @@ -130,7 +130,7 @@ public List GetTerrainTypeGroups() public void LoadConfig(TerrainGeneratorConfiguration configuration) { - for (int i = 0; i < configuration.TerrainTypeGroups.Count; i++) + for (int i = 0; i < configuration.TerrainTypeGroups.Count && i < MaxTerrainTypeGroupCount; i++) { var ttGroup = configuration.TerrainTypeGroups[i]; diff --git a/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTileGroupsPanel.cs b/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTileGroupsPanel.cs index 6657c12f..41611d49 100644 --- a/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTileGroupsPanel.cs +++ b/src/TSMapEditor/UI/Windows/TerrainGenerator/TerrainGeneratorTileGroupsPanel.cs @@ -18,6 +18,8 @@ namespace TSMapEditor.UI.Windows.TerrainGenerator /// public class TerrainGeneratorTileGroupsPanel : EditorPanel { + private const int MaxTileGroupCount = 8; + public TerrainGeneratorTileGroupsPanel(WindowManager windowManager, Map map) : base(windowManager) { this.map = map; @@ -36,8 +38,6 @@ public TerrainGeneratorTileGroupsPanel(WindowManager windowManager, Map map) : b public override void Initialize() { - const int MaxTileGroupCount = 8; - tileSetSelectors = new EditorPopUpSelector[MaxTileGroupCount]; tileIndices = new EditorTextBox[MaxTileGroupCount]; tileGroupOpenChances = new EditorNumberTextBox[MaxTileGroupCount]; @@ -175,7 +175,7 @@ public List GetTileGroups() public void LoadConfig(TerrainGeneratorConfiguration configuration) { - for (int i = 0; i < configuration.TileGroups.Count; i++) + for (int i = 0; i < configuration.TileGroups.Count && i < MaxTileGroupCount; i++) { var tileGroup = configuration.TileGroups[i];