Author Topic: Crashes related to ruleset file load order  (Read 872 times)

Offline Delian

  • Commander
  • *****
  • Posts: 547
    • View Profile
Re: Crashes related to ruleset file load order
« Reply #15 on: December 16, 2024, 10:01:20 pm »
I have found only two usages outside of this file, and they are probably mistakes.

So cruel to call them mistakes! They work fine! (as long as file loading is z-a)

And here's an example of some problems resulting from different locales: https://openxcom.org/forum/index.php?topic=5146.msg83361#msg83361

...

...

No, that problem wasn't due to different locales. It was due to duplicate folder names between common/SoldierName and Celebrate_Diversity/SoldierName.
The problem was that common/SoldierName has "argentina.nam", but Celebrate_Diversity does not (it has "argentinian.nam"). So after merging the two virtual dirs, this extra file causes the offset.
Note that, even though we were already using std::sort() for rul files back then, that doesn't apply to soldier names. For soldier names we explicitly call a locale-aware sort.
« Last Edit: December 16, 2024, 10:30:42 pm by Delian »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9136
    • View Profile
Re: Crashes related to ruleset file load order
« Reply #16 on: December 17, 2024, 09:47:56 am »
No, that problem wasn't due to different locales.

Yes, it WAS also due to different locales!
Don't make me an idiot.

Both duplicate folder and locale issue needed to be fixed.
Fixing just one still lead to offset issues.
Different problems, same result for the player... dysfunctional mod.
« Last Edit: December 17, 2024, 09:49:55 am by Meridian »

Offline Delian

  • Commander
  • *****
  • Posts: 547
    • View Profile
Re: Crashes related to ruleset file load order
« Reply #17 on: December 17, 2024, 02:53:19 pm »
Ok, but back then soldier name files were not yet being sorted locale-aware. Stoddard only made namepool sorting locale-aware 5 years ago.

Yes, I agree that there are some problems resulting from sorting in different locales. I am with you on that.

For demonstration:
Let's say that a modder defines "Flag25" to be Resources/Flags/Kenya.png.
How did the modder determine that Flag25 is Kenya? He looked at the SoldierNames (or whatever) folder and saw that the 26th file was Kenyan.nam
So nationality with index 25 is Kenya. Soldier with _nationality = 25 will get this flag.
Soldier also gets a name from names[_nationality]. So the name pool with index 25 will be used for the name. names vector was generated after locale-aware sorting files.
As you can guess, this will fail in other locales, because there's no guarantee that Kenyan.nam will be the 26th file after applying a locale-aware sort.
I don't know why Stoddard made name pool sorting locale-aware. It seems like a really bad idea to do that :D
To being with, anything (_nationality included) referring to the index position of a file in a folder is too fragile and is simply bound to fail one way or another. Add or remove a file and it fails.

So, uhh, what were we talking about again? Ruleset load order... yeah... so there's an issue that a lot of mods rely on the order the rul files are loaded in, while modders don't have any ability to specify what the order is. If you wish, I can try implementing something that would give modders some control over this order.