Index was outside the bounds of an array

Discuss modding questions and implementation details.
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Index was outside the bounds of an array

Post by Ralzar »

I split this out into a new topic since this might not be a 0.10.25 issue. But has probably been here since 0.10.24 without us spotting it.


TheLacus wrote: Sat Jul 18, 2020 12:55 pm Your mod is relatively big so it's not easy to find out what exactly is causing this issue. I'd suggest to consider compiling most, if not all, of your mod using Visual Studio and load the assembly at run time from resulting .dll file, but I understand this might be overwhelming.
I spent the day doing some serious digging. And the result so far is... strange.


I took my C&C code and stripped it down to a few lines of code, then built it up piece by piece. For each bit of code, building a new dfmod file and running it in a clean version of 0.10.25a in the Unity editor, containing only the dfmod files of my mods.

Note: With the complete version of C&C, four "Index was outside the bounds of an array" errors would appear when loading it with my other mods.

With only a few lines of code, no errors occurred.

I built and built without anything happening. Until I only had the main methods left. Before I even got that far, the error occurred. But only one error, not four. So I stopped adding and started pruning the code to see what exact line caused it.

And I wound up with... no specific line. It is the LENGTH of the script that is the problem. I confirmed this by removing enough of the code to not get the error and then I added:

//error?

in an unimportant spot in the code. And then I got "Index was outside the bounds of an array" again.

I haven't tested it yet, but in theory, I could make this error happen by taking a mod without the error and just add enough commented out lines to it?

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: ndex was outside the bounds of an array

Post by Magicono43 »

I can confirm that i'm having the same/similar issues with my Physical Combat And Armor Overhaul. If my PCO is loading before certain mods, this error will show up during mod initialization and cause effected mods loaded afterward to fail being initialized. But if PCO is loaded AFTER all of these mods, there will be no error.

I tried loading C&C and PCO alternating between loading before and after each other, and only one configuration was not giving errors, but the other was, this is very strange, so i'm not sure if it's based on length, but it could be possible.

Also as a note, this only seems to happen when the "problem" mods are in a .dfmod bundled "live" form, not in virtual forms. Which makes me thing it has to do something with how the mods are being read in their binary forms as strings, and something gets screwed up along the way of the initialization.

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Index was outside the bounds of an array

Post by Ralzar »

Ok, I tried just adding a bunch of commented out lines to another mod, but could not reproduce the error. So it's not length directly, but something else in the code that seems to react to the mods length. It's probably not a coincidence that it's both mine and Magiconos longest mods that cause this error.

User avatar
Hazelnut
Posts: 3016
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Index was outside the bounds of an array

Post by Hazelnut »

Well this code is being complied at runtime so length & complexity could very well cause issues like that. Refactoring into multiple classes or at least files should work around it. Alternatively you could build an assembly as TheLacus suggested, although I have no idea what that involves. (C# noob myself)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Index was outside the bounds of an array

Post by Ralzar »

So, I just discovered Realistic Wagon has the same error. Which is annoying, but at least handy in the sense that Realistic Wagon is a lot smaller and more managable than Climates & Calories.

https://github.com/Ralzar81/Realistic-Wagon

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Index was outside the bounds of an array

Post by Ralzar »

Hazelnut wrote: Sun Jul 19, 2020 8:27 am Well this code is being complied at runtime so length & complexity could very well cause issues like that. Refactoring into multiple classes or at least files should work around it. Alternatively you could build an assembly as TheLacus suggested, although I have no idea what that involves. (C# noob myself)
I actually tried today to split C&C into 5 separate mods. The error still occurred when the mod with the main script (climatescalories.cs) ran.

I just downloaded burts tent demo, which Realisitc Wagon is mostly based on. That did not have the error, so I'll try to do some comparisons between the two and see what I do differently.

User avatar
Interkarma
Posts: 7242
Joined: Sun Mar 22, 2015 1:51 am

Re: Index was outside the bounds of an array

Post by Interkarma »

Ralzar wrote: Sat Jul 18, 2020 10:31 pm I split this out into a new topic since this might not be a 0.10.25 issue. But has probably been here since 0.10.24 without us spotting it.
This could be. There were updates to mod framework in 0.10.24, unlike .25 that was just a straight engine upgrade over .24.

What's the best/quickest mod combination to reproduce index out of bounds? I'll chase this down as a regression from .24 and go hunting.

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Index was outside the bounds of an array

Post by Ralzar »

I really wish I could give you an easy mod to do this with, but only my Climates&Calories and Magiconos Physical Combat mod causes this (as far as we know/have confirmed).

Adding a zip of C&C plus Realistic Wagon, me and Hazelnut used earlier today to hunt for the cause.

These were built by Hazelnut in his 0.10.25a with my github code.

To sum up how to recreate the bug:

Load these two mods into StreamingAssets/Mods in the master. Open the master in Unity. Try to run the game. As soon as you see the "Start New Game" screen you will have these errors in your logs:
1.png
1.png (342.19 KiB) Viewed 1911 times
2.png
2.png (10.04 KiB) Viewed 1911 times
Then in the player.log (in AppData) you will see the same log created if you run it in live:

Code: Select all

DFTFU 1.8.9: scene index = 1 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

ModManager - started loading mod: Climates & Calories 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

ModManager - started loading mod: Realistic Wagon 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

Error (): Index was outside the bounds of the array.
 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

ModManager - init finished.  Mod Count: 2 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)

Note: this will only happen if you load C&C first, then Realistic Wagon. If you add more mods after realistic wagon, the number of errors will increase. (Possibly based on the length of C&C. When I shortened the C&C code down, the number of errors decreased.)
Mods.zip
(226.21 KiB) Downloaded 119 times

Edit: Oh yeah, and if you start the game with C&C and just die right away when you load a savegame: you're probably starving to death. Eat/drink in a tavern and save..
Last edited by Ralzar on Sun Jul 19, 2020 8:51 pm, edited 1 time in total.

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: Index was outside the bounds of an array

Post by Magicono43 »

Interkarma wrote: Sun Jul 19, 2020 8:30 pm
Ralzar wrote: Sat Jul 18, 2020 10:31 pm I split this out into a new topic since this might not be a 0.10.25 issue. But has probably been here since 0.10.24 without us spotting it.
This could be. There were updates to mod framework in 0.10.24, unlike .25 that was just a straight engine upgrade over .24.

What's the best/quickest mod combination to reproduce index out of bounds? I'll chase this down as a regression from .24 and go hunting.
From our testing, it appears to not be related to version. I had seen this same error happen probably as early as 0.10.23, but did not give it much notice at the time, then Ralzar noticed it in 0.10.24 and realized it was causing certain mods to not load properly lower down in the load order list. So fortunately, this does not seem to be an issue with 0.10.25 or the Unity engine being updated.

User avatar
Interkarma
Posts: 7242
Joined: Sun Mar 22, 2015 1:51 am

Re: Index was outside the bounds of an array

Post by Interkarma »

Thank you guys. I'll throw another set of eyes on this when I can later today in Aussie-time.

Post Reply