Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8865e20b1140
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1ed6360ac80e
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 16, 2020

  1. Do not enter the C++ code with positions, velocities or angular veloc…

    …ities that are NaNs.
    pleroy committed Apr 16, 2020
    Copy the full SHA
    84fb522 View commit details
  2. Merge pull request #2532 from pleroy/2530

    Do not call C++ with positions, velocities or angular velocities that are NaNs.
    pleroy authored Apr 16, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1ed6360 View commit details
Showing with 31 additions and 18 deletions.
  1. +3 −3 geometry/r3x3_matrix_body.hpp
  2. +2 −2 journal/player_test.cpp
  3. +2 −0 ksp_plugin/part.hpp
  4. +24 −13 ksp_plugin_adapter/ksp_plugin_adapter.cs
6 changes: 3 additions & 3 deletions geometry/r3x3_matrix_body.hpp
Original file line number Diff line number Diff line change
@@ -162,12 +162,12 @@ R3Element<Quotient<RScalar, Scalar>> R3x3Matrix<Scalar>::Solve(
max = Abs(A(i, k));
}
}
CHECK_LE(0, r);
CHECK_GT(3, r);
CHECK_LE(0, r) << *this << " cannot pivot";
CHECK_GT(3, r) << *this << " cannot pivot";
std::swap(A.rows_[k], A.rows_[r]);
std::swap(L.rows_[k], L.rows_[r]);
std::swap(b[k], b[r]);
CHECK_NE(Scalar{}, A(k, k));
CHECK_NE(Scalar{}, A(k, k)) << *this << " is singular";

for (int j = k; j < 3; ++j) {
Scalar U_kj = A(k, j);
4 changes: 2 additions & 2 deletions journal/player_test.cpp
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ TEST_F(PlayerTest, DISABLED_SECULAR_Debug) {
// An example of how journaling may be used for debugging. You must set
// |path| and fill the |method_in| and |method_out_return| protocol buffers.
std::string path =
R"(P:\Public Mockingbird\Principia\Crashes\2507\JOURNAL.20200328-214524)"; // NOLINT
R"(P:\Public Mockingbird\Principia\Crashes\2530\JOURNAL.20200416-093807)"; // NOLINT
Player player(path);
int count = 0;
while (player.Play(count)) {
@@ -109,7 +109,7 @@ TEST_F(PlayerTest, DISABLED_SECULAR_Debug) {
auto* extension = method_in.MutableExtension(
serialization::CatchUpLaggingVessels::extension);
auto* in = extension->mutable_in();
in->set_plugin(2014156823824);
in->set_plugin(2899402431696);
}
serialization::Method method_out_return;
{
2 changes: 2 additions & 0 deletions ksp_plugin/part.hpp
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ class Part final {

PartId part_id() const;

// When a part is not truthful, all its properties except for name and part_id
// are lies and should not be propagated to the game.
bool truthful() const;
void make_truthful();

37 changes: 24 additions & 13 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -550,6 +550,24 @@ private static bool JustAboveTheGround(Vessel vessel,
return height + vertical_speed * Δt < 0;
}

private static bool IsNaN(Vector3d v) {
return double.IsNaN(v.x + v.y + v.z);
}

private static bool IsNaN(XYZ xyz) {
return double.IsNaN(xyz.x + xyz.y + xyz.z);
}

// It seems that parts sometimes have NaN position, velocity or angular
// velocity, presumably because they are being destroyed. Just skip these
// unfaithful parts as if they had no rigid body.
private static bool PartIsFaithful(Part part) {
return part.rb != null &&
!IsNaN(part.rb.position) &&
!IsNaN(part.rb.velocity) &&
!IsNaN(part.rb.angularVelocity);
}

private void OverrideRSASTarget(FlightCtrlState state) {
if (override_rsas_target_ && FlightGlobals.ActiveVessel.Autopilot.Enabled) {
FlightGlobals.ActiveVessel.Autopilot.SAS.SetTargetOrientation(
@@ -1045,7 +1063,7 @@ private System.Collections.IEnumerator WaitedForFixedUpdate() {
!vessel.packed,
out bool inserted);
if (!vessel.packed) {
foreach (Part part in vessel.parts.Where((part) => part.rb != null)) {
foreach (Part part in vessel.parts.Where(PartIsFaithful)) {
QP degrees_of_freedom;
if (part_id_to_degrees_of_freedom_.ContainsKey(part.flightID)) {
degrees_of_freedom = part_id_to_degrees_of_freedom_[part.flightID];
@@ -1224,10 +1242,7 @@ private System.Collections.IEnumerator WaitedForFixedUpdate() {
if (!plugin_.HasVessel(vessel.id.ToString())) {
continue;
}
foreach (Part part in vessel.parts) {
if (part.rb == null) {
continue;
}
foreach (Part part in vessel.parts.Where(PartIsFaithful)) {
if (main_body_change_countdown_ == 0 &&
last_main_body_ == FlightGlobals.ActiveVessel?.mainBody) {
plugin_.PartSetApparentRigidMotion(
@@ -1270,10 +1285,7 @@ private System.Collections.IEnumerator WaitedForFixedUpdate() {
if (!plugin_.HasVessel(vessel.id.ToString())) {
continue;
}
foreach (Part part in vessel.parts) {
if (part.rb == null) {
continue;
}
foreach (Part part in vessel.parts.Where(PartIsFaithful)) {
QPRW part_actual_motion =
plugin_.PartGetActualDegreesOfFreedom(
part.flightID,
@@ -1463,7 +1475,7 @@ private void FashionablyLate() {
foreach (Vessel vessel in
FlightGlobals.Vessels.Where(v => is_manageable(v) &&
!v.packed)) {
foreach (Part part in vessel.parts.Where((part) => part.rb != null)) {
foreach (Part part in vessel.parts.Where(PartIsFaithful)) {
if (part.torque != Vector3d.zero) {
part_id_to_intrinsic_torque_.Add(part.flightID, part.torque);
}
@@ -1555,7 +1567,7 @@ private void BetterLateThanNever() {
foreach (Vessel vessel in
FlightGlobals.Vessels.Where(v => is_manageable(v) &&
!v.packed)) {
foreach (Part part in vessel.parts.Where((part) => part.rb != null)) {
foreach (Part part in vessel.parts.Where(PartIsFaithful)) {
// TODO(egg): use the centre of mass.
part_id_to_degrees_of_freedom_.Add(
part.flightID,
@@ -1651,8 +1663,7 @@ private void RenderGuidance(Vessel active_vessel) {
Burn burn = plugin_.FlightPlanGetManoeuvre(
vessel_guid,
first_future_manœuvre_index.Value).burn;
if (flight_planner_.show_guidance &&
!double.IsNaN(guidance.x + guidance.y + guidance.z)) {
if (flight_planner_.show_guidance && !IsNaN(guidance)) {
// The user wants to show the guidance node, and that node was
// properly computed by the C++ code.
PatchedConicSolver solver = active_vessel.patchedConicSolver;