Nivekk / KOS

Fully programmable autopilot mod for KSP.
Other
80 stars 30 forks source link

kOS breaks vessel loading when the context includes certain variable values #220

Open tsbockman opened 10 years ago

tsbockman commented 10 years ago

If the kOS unit context includes a set variable with a very large or very small absolute value, that value gets written to the quicksave or persistence file in scientific notation. When attempting to reload the vessel later, kOS throws an exception and interrupts the process, preventing the rest of the parts from loading.

Steps to reproduce: 1) Load a simple vessel with a kOS unit on the launch pad. 2) Open the kOS terminal and execute the following command:

set test to 10^(0-50).

3) Quicksave. (Look in quicksave.sfs, and you should now see "test = 1E-50" in the variables section.) 4) Quickload... or rather try, because at this point it will log a "kOSException" and get stuck with the vessel only partially loaded.

Removing the "test=1E-50" or removing the "E-50" will make it possible to load the vessel again, albeit with an altered kOS context now.

From the user's perspective, this bug is extremely frustrating and mysterious, as it will cause scripts that automatically calculate and set variable values to sometimes break vessel saves, but not others, depending on whether the values set right before saving triggered scientific notation or not.

baloan commented 10 years ago

Confirmed with KSP 0.22.0 and uploads_2013_11_kOS_0_9_2.zip which reports version as 0.9.1 though. After deleting two variables with scientific notation values from persistent.sfs I could load the vessel without problems. A quick fix release is appreciated.

Dunbaratu commented 10 years ago

Does this only affect the saved file or does it also affect going on rails and then off rails again? I ask because I frequently get KSP to grind to a lagged halt by leaving a program running on a vessel that goes on rails. When I go back to the vessel and reload it into the full phyics engine, the game gets laggy for a few frames of animation and then grinds to a total halt and has to be killed externally. When this happens it's usually accompanied by a vessel losing half its parts when it gets reloaded from rails to full physics.

a1270 commented 10 years ago

Two things are going on it seems. The major issue is the value is being split up, it tries to subtract 50 from 1E. The other, which doesn't even come to play because of the first, is a missing NumberStyles.AllowExponent on RecognizeConstants. Adding a scientific notion type is what i am thinking but i'll let @Nivekk handle this.

tsbockman commented 10 years ago

If kOS is using the full expression parser to process stored variable values, another option would be to just detect out of range values when saving and store them using kOS' current exponentiation syntax instead of C#'s standard "E" notation.

Also, I just wanted to say thanks to all the developers working on this plugin, especially Nivekk. kOS is rather quirky right now, but it is still one of the coolest add-ons available for KSP. I'm looking forward to seeing a proper version 1.0 some day.

JoCRaM commented 10 years ago

I Confirm this happens in what spaceport calls kOS 0.9.2 (shows version 0.9.1 from the terminal) 117,248 bytes. the problem exhibits when switching between vessels. I get an [Exception] ArgumentOutOfRangeException: Cannot be negative. Parameter name length

by deleteing the variables from the persistence file I can continue to use the craft - but there's nothing obviously wrong with them:

by quickload elimination I was able to verify strings are also a problem. they can be fixed by deletion, or by using double quotes..

                        misst = 28301.351
                        yaw = 90
                        pitch = -0.000156820358441223
                        throttledemand = 0
                        uphill = 1.29739911239655
                        targetalt = 74000
                        targetg = 2
                        throttleclip = 0
                        launchspeed = 100.083789574058
                        message = Mission end: 74.3x74
                        start = 28301.351
                        uphilldemand = 0.014415545693295
                        apotiming = -0.6608577299185
                        apoclip = 0
                        mess = Mission end: 74.3x74
baloan commented 10 years ago

Also breaks when you do

set ship-delta to 0.