Skip to content

Commit

Permalink
Fix crashes if a terrain generator preset contains too many entries f…
Browse files Browse the repository at this point in the history
…or smudges, terrain objects or tiles
  • Loading branch information
Rampastring committed Mar 12, 2024
1 parent 996552a commit b1d3315
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace TSMapEditor.UI.Windows.TerrainGenerator
/// </summary>
public class TerrainGeneratorSmudgeGroupsPanel : EditorPanel
{
private const int MaxSmudgeTypeGroupCount = 8;

public TerrainGeneratorSmudgeGroupsPanel(WindowManager windowManager, Map map) : base(windowManager)
{
this.map = map;
Expand All @@ -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];
Expand Down Expand Up @@ -128,7 +128,7 @@ public List<TerrainGeneratorSmudgeGroup> 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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace TSMapEditor.UI.Windows.TerrainGenerator
/// </summary>
public class TerrainGeneratorTerrainTypeGroupsPanel : EditorPanel
{
private const int MaxTerrainTypeGroupCount = 8;

public TerrainGeneratorTerrainTypeGroupsPanel(WindowManager windowManager, Map map) : base(windowManager)
{
this.map = map;
Expand All @@ -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];
Expand Down Expand Up @@ -130,7 +130,7 @@ public List<TerrainGeneratorTerrainTypeGroup> 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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace TSMapEditor.UI.Windows.TerrainGenerator
/// </summary>
public class TerrainGeneratorTileGroupsPanel : EditorPanel
{
private const int MaxTileGroupCount = 8;

public TerrainGeneratorTileGroupsPanel(WindowManager windowManager, Map map) : base(windowManager)
{
this.map = map;
Expand All @@ -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];
Expand Down Expand Up @@ -175,7 +175,7 @@ public List<TerrainGeneratorTileGroup> 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];

Expand Down

0 comments on commit b1d3315

Please sign in to comment.