Laurens
Member
- Messages
- 11
- Reaction score
- 12
Title: Crash (ArgumentOutOfRangeException in TransferPlanner.DrawPlanWindow) when any vehicle is destroyed while the Transfer Planner is open
The window freezes on that frame and the process then exits ("abnormal-exit" log).
Game Version
2026.11.25.5949Operating System
Windows 11 Home (build 26300)What Happened
With the Transfer Planner open, destroying a different vehicle crashes the game on the next frame. KSA.exe was launched directly, with no mod loader and only Core enabled:
Code
Unhandled exception System.ArgumentOutOfRangeException: index ('5') must be less than '5'. (Parameter 'index')
at KSA.CelestialSystem.GetIndex(Int32 index)
at KSA.TransferPlanner.DrawPlanWindow(IGameViewport inViewport)
at KSA.Program.OnDrawUiThreadSafe(Double dt)
at KSA.Program.OnFrame(Double currentPlayerTime, Double dtPlayer)
at KSA.App.Run()
at KSA.Program.Main(String[] inArgs).
What Was Expected
Destroying a vehicle that isn't the planner's source or destination should leave the planner showing the same source. If the destroyed vehicle was the source or destination, the planner should clear that selection, as it does when the window is first opened. In neither case should the game crash.Reproduction Steps
- Launch KSA with no mods. In the configuration window, keep the defaults (System: Earth and Moon, Vehicle: Rocket, Location: Orbit around Earth) and press START KSA.
- Open the terminal with \ and enter:
duplicate Rocket Copy - Enter:
control Copy - Close the terminal (\) and open the Transfer Planner with F4. It shows SOURCE = Copy.
- Open the terminal again and enter:
destroy Rocket - The game crashes on the next frame with the exception above.
Reproduction Rate
Always (deterministic).Additional Info
- Video/Screenshots: none needed. The steps reproduce it every time, and the full log of the crashing run is attached.
- Save File: not needed. The steps start from a fresh game with the default settings.
- Other Notes:
Cause (from reading the code):TransferObjectstoresAstronomical.LookupIndex, a slot number inCelestialSystem._all, rather than the object.LookupCollection.Deregisterremoves an item by moving the last item into the freed slot and shrinking the list. As a result,TransferPlanner._sourceBody/_destinationBodygo stale whenever any vehicle is removed:- If the planner's vehicle was last in the list and an earlier vehicle is removed, the stored index equals the new Count, so
GetIndexthrows (this report). In the steps above, Copy was created last (index 5),destroy Rocketmoved Copy into Rocket's slot, and the planner still asked for index 5 of 5. - If the planner's vehicle itself is removed, the stored index now refers to whichever vehicle was moved into the slot. The planner silently switches to an unrelated vehicle, and code that needs a Vehicle can hit a NullReferenceException in
DrawPlanWindow. CelestialSystem.Rename(deregister + register) moves indices around in the same way.
destroycommand. A natural repro is a save that already has debris, a newly launched craft planned from, and then Clear Debris. Multiplayer mods make it frequent, because remote players' craft are added and removed all the time; one player crashed this way five times in a day.
Suggested fix: haveTransferObjecthold theAstronomical(or its Id/hash) instead of the slot index, and treat a disposed or missing body as "N/A". Or reset the planner's selections fromCelestialSystem.Deregister.
Related, same window (found by reading the code; not reproduced on demand because it depends on timing): the porkchop calculation (TransferTask.WorkerTask.CalculateAutomaticTransfer → OrbitalTransfers.BuildFlightPlan → FlightPlan.CalculateConicPatch) enumeratespatch.PrimaryBody.Childrenon thread-pool threads. Meanwhile the main thread adds to or removes from those lists, through staging (AdoptSeparatedVehicle), SOI changes (ApplyPendingParentChildrenFix), new vehicles andCelestialSystem.Deregister. If that happens during CALCULATE, the worker throws an unhandled "Collection was modified; enumeration operation may not execute" and the process exits. Seen in the field:
Workers should iterate a snapshot of the children, and an exception in a worker should not take down the process.CodeUnhandled exception System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Collections.Generic.List`1.Enumerator.MoveNext() at KSA.FlightPlan.CalculateConicPatch(...) at KSA.FlightPlan.ComputeCompleteTrajectory(...) at KSA.OrbitalTransfers.BuildFlightPlan(...) at KSA.TransferTask.WorkerTask.CalculateAutomaticTransfer(...) at KSA.TransferTask.WorkerTask.ThreadPoolCallback(Object threadContext) - If the planner's vehicle was last in the list and an earlier vehicle is removed, the stored index equals the new Count, so
Attachments
Upvote
1