Open Ernesto-Alvarez opened 3 years ago
This is one place where I get frustrated at how much of the KSP game's "universe rules" are implemented inside the game's GUI code instead of being in a deeper layer that the GUI code merely calls. That makes it a PITA for kOS to obey the universe's rules since it bypasses the GUI code.
kOS had to invent it's own resource transfer system since the stock one is inside the GUI code, and it looks like we didn't do a good enough job checking for negatives like this.
I agree that the best fix would be to make it so a negative amount isn't an error, but it just basically means you're just swapping source and destination around.
Attempting to create a resource transfer with a negative amount of resources ends up creating resources in the source part without taking them from the destination. For this to work, the parts MUST NOT be full.
Reproduction steps.
Tanks are denominated as A to D, from top to bottom. All tanks should be half full at the beginning of the test. The program attempts to transfer -50 units of fuel from tank A to tank D. Tank A should have an extra 50 units at the end, without draining any of the other tanks (tank D was the target tank).
The bug is not caused by excessive transfer, programming a lesser (not so) negative amount to be transferred will cause the same amount to appear at the source tank, even if we're transferring less than 45 units. The source tank may end up being "overfilled" due to the negative transfer if this negative transfer is too big.
Possible solutions could be to check the boundaries, preventing negative transfers or to transfer from destination to source if negative values are input (that would make me REALLY happy, as it would mean not having to deal with abs() and lots of conditionals)