From 0f6eb16b7b2969d0edd89961907e70a256ae5c14 Mon Sep 17 00:00:00 2001 From: pleroy Date: Sat, 26 Oct 2024 15:52:14 +0200 Subject: [PATCH 1/3] Make sure that a deserialized flight plan exists before accessing the flight plan. --- ksp_plugin/interface_planetarium.cpp | 15 +++++++++------ ksp_plugin/plugin.cpp | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ksp_plugin/interface_planetarium.cpp b/ksp_plugin/interface_planetarium.cpp index 1ab5a06ac2..eb5420106a 100644 --- a/ksp_plugin/interface_planetarium.cpp +++ b/ksp_plugin/interface_planetarium.cpp @@ -345,13 +345,16 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory( *minimal_distance_from_camera = std::numeric_limits::infinity(); return m.Return(); } else { - auto const& vessel = *plugin->GetVessel(vessel_guid); + auto& vessel = *plugin->GetVessel(vessel_guid); Instant const prediction_final_time = vessel.prediction()->t_max(); - Instant const final_time = - vessel.has_flight_plan() - ? std::max(vessel.flight_plan().actual_final_time(), - prediction_final_time) - : prediction_final_time; + Instant final_time; + if (vessel.has_flight_plan()) { + vessel.ReadFlightPlanFromMessage(); + final_time = std::max(vessel.flight_plan().actual_final_time(), + prediction_final_time); + } else { + final_time = prediction_final_time; + } auto const& celestial_trajectory = plugin->GetCelestial(celestial_index).trajectory(); // No need to request reanimation here because the current time of the diff --git a/ksp_plugin/plugin.cpp b/ksp_plugin/plugin.cpp index 4445b06f7b..64cdb07871 100644 --- a/ksp_plugin/plugin.cpp +++ b/ksp_plugin/plugin.cpp @@ -971,6 +971,7 @@ void Plugin::ExtendPredictionForFlightPlan(GUID const& vessel_guid) const { // no guarantee that it will be long enough. Presumably the user will keep // increasing the flight plan length and get what they want, ultimately. if (renderer_->HasTargetVessel() && vessel.has_flight_plan()) { + vessel.ReadFlightPlanFromMessage(); auto& target_vessel = renderer_->GetTargetVessel(); if (target_vessel.prediction()->back().time < vessel.flight_plan().actual_final_time()) { From d8d89f4ccbdbdd25e1330fe4aa78013a20e57f72 Mon Sep 17 00:00:00 2001 From: pleroy Date: Sat, 26 Oct 2024 15:59:18 +0200 Subject: [PATCH 2/3] We have a utility for that. --- ksp_plugin/interface_planetarium.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ksp_plugin/interface_planetarium.cpp b/ksp_plugin/interface_planetarium.cpp index eb5420106a..1ab5a06ac2 100644 --- a/ksp_plugin/interface_planetarium.cpp +++ b/ksp_plugin/interface_planetarium.cpp @@ -345,16 +345,13 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory( *minimal_distance_from_camera = std::numeric_limits::infinity(); return m.Return(); } else { - auto& vessel = *plugin->GetVessel(vessel_guid); + auto const& vessel = *plugin->GetVessel(vessel_guid); Instant const prediction_final_time = vessel.prediction()->t_max(); - Instant final_time; - if (vessel.has_flight_plan()) { - vessel.ReadFlightPlanFromMessage(); - final_time = std::max(vessel.flight_plan().actual_final_time(), - prediction_final_time); - } else { - final_time = prediction_final_time; - } + Instant const final_time = + vessel.has_flight_plan() + ? std::max(vessel.flight_plan().actual_final_time(), + prediction_final_time) + : prediction_final_time; auto const& celestial_trajectory = plugin->GetCelestial(celestial_index).trajectory(); // No need to request reanimation here because the current time of the From b1e09dcc490f7db52e7e3e4c363c6b2d07e99f5a Mon Sep 17 00:00:00 2001 From: pleroy Date: Sat, 26 Oct 2024 15:59:18 +0200 Subject: [PATCH 3/3] We have a utility for that. --- ksp_plugin/interface_planetarium.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ksp_plugin/interface_planetarium.cpp b/ksp_plugin/interface_planetarium.cpp index eb5420106a..b09912c08c 100644 --- a/ksp_plugin/interface_planetarium.cpp +++ b/ksp_plugin/interface_planetarium.cpp @@ -345,16 +345,13 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory( *minimal_distance_from_camera = std::numeric_limits::infinity(); return m.Return(); } else { - auto& vessel = *plugin->GetVessel(vessel_guid); + auto const& vessel = *plugin->GetVessel(vessel_guid); Instant const prediction_final_time = vessel.prediction()->t_max(); - Instant final_time; - if (vessel.has_flight_plan()) { - vessel.ReadFlightPlanFromMessage(); - final_time = std::max(vessel.flight_plan().actual_final_time(), - prediction_final_time); - } else { - final_time = prediction_final_time; - } + Instant const final_time = + vessel.has_flight_plan() + ? std::max(GetFlightPlan(*plugin, vessel_guid).actual_final_time(), + prediction_final_time) + : prediction_final_time; auto const& celestial_trajectory = plugin->GetCelestial(celestial_index).trajectory(); // No need to request reanimation here because the current time of the