Skip to content

Commit

Permalink
Fixed a bug that can cause an indexoutofbounds exception when generat…
Browse files Browse the repository at this point in the history
…ing more belts than there are letters in the greek alphabet
  • Loading branch information
thorwin99 committed Sep 1, 2020
1 parent b92530f commit b777edd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 0 additions & 2 deletions SEWorldGenPlugin/GUI/PluginWorldSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ protected override void BuildControls()

if (m_isNewGame)
{
PluginLog.Log(MySettings.Static.Settings.ToString());
PlSettings = MySettings.Static.Settings.copy();
PluginLog.Log(PlSettings.ToString());
//PlSettings.GeneratorSettings.FirstPlanetCenter = MySettings.Static.Settings.GeneratorSettings.FirstPlanetCenter;
//PlSettings.GeneratorSettings.PlanetSettings.BlacklistedPlanets = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.BlacklistedPlanets;
//PlSettings.GeneratorSettings.PlanetSettings.Moons = MySettings.Static.Settings.GeneratorSettings.PlanetSettings.Moons;
Expand Down
4 changes: 2 additions & 2 deletions SEWorldGenPlugin/Generator/SystemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private void GenerateBelt(long distance, ref int beltIndex)

string name = SettingsSession.Static.Settings.GeneratorSettings.BeltSettings.BeltNameFormat
.SetProperty("ObjectNumber", beltIndex + 1)
.SetProperty("ObjectNumberGreek", greek_letters[beltIndex])
.SetProperty("ObjectNumberGreek", greek_letters[beltIndex % greek_letters.Length])

This comment has been minimized.

Copy link
@Horathio

Horathio Sep 1, 2020

Contributor

While this should fix the crash if there are more belts created than there are letters in the greek alphabet, wouldn't it then create 2x 'Belt Alpha', 2x 'Belt Beta' etc? From what I can tell, it just starts over with the first index again. This is going to be confusing. Also, at that point you already have 24 belts in your system for this to become a problem.

I'd rather see the number of generated belts capped at 24, so when the list of names is exhausted, no new belts will be generated. Alternatively, appending the name of any belts past the 24th by another signifier would be helpful, so you don't end up with confusing names. E.g. 'Belt Alpha' and 'Belt Alpha Alpha', 'Belt Alpha *', 'Belt Alpha Outer' etc. I highly doubt there is a need to go beyond 48 belts though, so capping it at twice the length of the greek alphabet is more than reasonable I think if you don't want to come up with even more identifiers.

As the crash should be fixed by this, any further changes are not urgent, just my two cents about the consequences of this change.

This comment has been minimized.

Copy link
@thorwin99

thorwin99 Sep 1, 2020

Author Owner

i know that, and thats how it has been before i did the change to the naming system. It jsut overcomplicates things to either cap them or add secondary, etc. letters. Also, the same problem exists with normal letters. Once all 26 have been used, there will be duplicate names.

.SetProperty("ObjectNumberRoman", ConvertNumberToRoman(beltIndex + 1))
.SetProperty("ObjectLetterLower", (char)('a' + (beltIndex % 26)))
.SetProperty("ObjectLetterUpper", (char)('A' + (beltIndex % 26)));
Expand Down Expand Up @@ -285,7 +285,7 @@ private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity,

string name = SettingsSession.Static.Settings.GeneratorSettings.PlanetSettings.MoonNameFormat
.SetProperty("ObjectNumber", i + 1)
.SetProperty("ObjectNumberGreek", greek_letters[i])
.SetProperty("ObjectNumberGreek", greek_letters[i % greek_letters.Length])
.SetProperty("ObjectNumberRoman", ConvertNumberToRoman(i + 1))
.SetProperty("ObjectLetterLower", (char)('a' + (i % 26)))
.SetProperty("ObjectLetterUpper", (char)('A' + (i % 26)))
Expand Down
2 changes: 1 addition & 1 deletion SEWorldGenPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.6.2")]
[assembly: AssemblyVersion("1.7.6.3")]
[assembly: AssemblyFileVersion("1.0.0")]

0 comments on commit b777edd

Please sign in to comment.