mockingbirdnest / Principia

𝑛-Body and Extended Body Gravitation for Kerbal Space Program
MIT License
769 stars 69 forks source link

Crash when switching to Instant Impulse #2781

Open lpgagnon opened 3 years ago

lpgagnon commented 3 years ago

Scenario: in low orbit around the moon, plotting maneuvers for a landing. Had just quickloaded, and noticed plotted trajectory didn't quite match what it was prior to quicksave. Started fiddling with things to see if it was just a refresh issue. Last thing I did was click "instant impulse", game froze, then CTD.

Log file created at: 2020/11/01 13:30:34
Running on machine: LPG-GTX
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
    @   00007FFA6C4D6360    google::LogMessageFatal::~LogMessageFatal [0x00007FFA6C4D635F+47]
    @   00007FFA47623AC3    principia__VesselVelocity [0x00007FFA47623AC2+314018]
    @   00007FFA476D066E    principia__VesselVelocity [0x00007FFA476D066D+1021517]
    @   00007FFA47536D9D    (No symbol) [0x00007FFA47536D9C]
    @   00007FFA4753E879    (No symbol) [0x00007FFA4753E878]
    @   00007FFA475C0C3F    principia__FlightPlanReplace [0x00007FFA475C0C3E+494]
    @   0000019AF14E43ED    (No symbol) [0x0000019AF14E43EC]
F1101 13:30:34.849426 15952 ephemeris_body.hpp:1200] Check failed: integrator_parameters.first_time_step > 0 * Second (-4.32489204406738281e+00 s vs. +0.00000000000000000e+00 s) Flow back to the future: -1.24250836271792316e+09 s <= -1.24250835839303112e+09 s

zipped INFO.log

pleroy commented 3 years ago

Decoded stack trace:

https://github.com/mockingbirdnest/Principia/blob/c0f911dc0e301755abf8847c656c264ed234c64a/ksp_plugin/interface_flight_plan.cpp#L492-L498 https://github.com/mockingbirdnest/Principia/blob/c0f911dc0e301755abf8847c656c264ed234c64a/ksp_plugin/flight_plan.cpp#L169-L199 https://github.com/mockingbirdnest/Principia/blob/c0f911dc0e301755abf8847c656c264ed234c64a/ksp_plugin/flight_plan.cpp#L395-L407 https://github.com/mockingbirdnest/Principia/blob/c0f911dc0e301755abf8847c656c264ed234c64a/ksp_plugin/flight_plan.cpp#L385-L385 https://github.com/mockingbirdnest/Principia/blob/c0f911dc0e301755abf8847c656c264ed234c64a/physics/ephemeris_body.hpp#L458-L474 https://github.com/mockingbirdnest/Principia/blob/c0f911dc0e301755abf8847c656c264ed234c64a/physics/ephemeris_body.hpp#L1166-L1200
pleroy commented 3 years ago

The log also has suspicious messages like:

I1101 12:07:26.290994  7936 flight_plan.cpp:320] Loading a flight plan with 1 anomalous segments and status FAILED_PRECONDITION: At time -1.24250734787396073e+09 s, step size is effectively zero.  Singularity or stiff system suspected.
E1101 13:29:51.749092 15952 interface_body.hpp:479] At time -1.24250735927222538e+09 s, step size is effectively zero.  Singularity or stiff system suspected.
pleroy commented 3 years ago

I believe that the check tells us that Ephemeris::FlowODEWithAdaptiveStep is called with a t that is strictly less than the end time of the trajectory. (Note the word "believe", the logic there is a bit tricky.)

We are called from FlightPlan::Replace, replacing a manœuvre in the flight plan because the user clicked "instant impulse". We do not know exactly the shape of the flight plan at the time of the crash or the manœuvre being replaced, but the last time the flight plan was loaded it was anomalous, and therefore was printed out. It looked like this (times in second since J2000):

initial_time:       -1242512439.579787
desired_final_time: -1242504055.6769223
manœuvre 0:
  initial_time:     -1242510250.6003575
  final_time:       -1242510235.6185611
  duration:                  14.981796301479443
manœuvre 1:
  initial_time:     -1242508622.9597487
  final_time:       -1242508362.7189230
  duration:                 260.24082569420426
manœuvre 2:
  initial_time:     -1242508362.7179232
  final_time:       -1242508262.5189014
  duration:                 100.19902178449944

It is worth noting that the last segment is anomalous. The last time the flight plan is integrated a singularity is encountered at time -1242507359.27226591 so the desired final time is not reached (presumably, the flight plan goes through the centre of a planet). Also interesting is the fact that the last two manœuvres are very close, being separated by 1 ms.

The t_final passed to the integrator is 1242508362.71792316 which matches the initial time of manœuvre 2 to the last digit. This tells us that we are recomputing the coast that ends at the beginning of that manœuvre. However, the end of the trajectory being prolonged (which should be at the fork point of the coast ending at manœuvre 2, i.e., the end of manœuvre 1) is -1242508358.39303112 (4 seconds into manœuvre 2). All of this points at a bug in the replacement of manœuvres, but it's hard to be more specific.

Two questions for @lpgagnon:

  1. Would you remember on which of the manœuvres you were clicking "instant impulse"?
  2. Is this a reproducible bug, i.e., could you give us a journal?
lpgagnon commented 3 years ago
  1. I don't, and wouldn't even venture a guess; I was clicking "harmless" things more or less at random
  2. Not reproducible; I've only seen it the one time.