KSPModdingLibs / KSPCommunityFixes

Community patches for bugs in the KSP codebase
49 stars 17 forks source link

Fix an IndexOutOfRangeException in DragCube.Load() #232

Open Nazfib opened 2 months ago

Nazfib commented 2 months ago

The name field in a DRAG_CUBE config node is supposed to be optional. However, when the name is not included in the list of values, an IndexOutOfRangeException is thrown.

Even when not loaded from a config file, when the name field on a DragCube object is the empty string (for example, when it is default-constructed in code) it is not included in the string returned by DragCube.SaveToString(); this causes a problem when the FlightIntegrator.Setup() method uses this string to clone drag cubes.

The first instructions in DragCube.Load(string[] data) are:

That last check should have been against a length of 24 instead; this patch replaces the first occurrence of ldc.i4.s 12 in the code by ldc.i4.s 24.

I've checked KSP version 1.0.5 (the oldest version available via Steam), and the bug was already present in that version; the code seems to be unchanged between then and version 1.12.5.