From 349cf40b775b1658f0630336c1b152b9f1e1f44f Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Sat, 11 Mar 2023 13:00:36 -0500 Subject: [PATCH] load many orbits to provoke failing assertions --- src/game.cpp | 15 +++++++++++++++ src/game.h | 2 +- src/main.cpp | 39 +++++++++++++++++++++++++++++++++++++-- src/orbits.cpp | 4 ++++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 5e7610d..5c469b0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,4 +1,6 @@ +#include + #include "game.h" @@ -243,6 +245,13 @@ applyManeuver(GameOrbit* orbit, ManeuverNode* maneuver) double mu = sys.body.mu; double r = orbitGetRadialDistance(sys.ep.e, sys.ep.p, theta); + // FIXME: debugging code + + GameOrbit old_orbit = *orbit; + if (!old_orbit.in_use) exit(1); // don't optimize out + + // FIXME: debugging code + dvec3 pos = orbitGetPositionVector(r, theta); dvec3 vel = orbitGetVelocityVector(mu, sys.h, sys.elements.e, theta); sys.rotation = orbitGetXForm(sys.elements); @@ -258,6 +267,12 @@ applyManeuver(GameOrbit* orbit, ManeuverNode* maneuver) // update satellite true anamoly sys.sat.theta = sys.elements.nu; + // FIXME: testing for instances where an orbit goes awry + glm::dvec3 sat_pos = sys.sat.position; + assert(!isnan(sat_pos.x) && !isnan(sat_pos.y) && !isnan(sat_pos.z)); + glm::dvec3 sat_vel = sys.sat.velocity; + assert(!isnan(sat_vel.x) && !isnan(sat_vel.y) && !isnan(sat_vel.z)); + // update ellipse3D & GLBuffer vertices ellipse3DUpdate(sys.rotation, sys.ep, orbit->e3d); GLBuffer* buf = &orbit->ellipse_entity->meshes[0].vertex_attrib_buffers[0]; diff --git a/src/game.h b/src/game.h index 10102d1..2752460 100644 --- a/src/game.h +++ b/src/game.h @@ -97,7 +97,7 @@ void selectOrbit(GameState* gs, GameOrbit* orbit); bool addManeuver(GameState* gs, GameOrbit* orbit, ImpulseType impulse_type, - double true_anomaly, + double true_anomaly = 0.f, double impulse_delta_v = 0.f); bool testManeuverStep(ManeuverNode* maneuver, diff --git a/src/main.cpp b/src/main.cpp index 5659bb6..f75a2d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ * - Important!! add std::isnan() checks, from , after applyManeuver(), * we're getting intermittent wonkyness, maybe another divide by zero * somewhere + * - to aid testing, we should create many more orbits, all with additional + * maneuver nodes */ #include @@ -241,6 +243,36 @@ loadOrbit(GameState* gs, return orbit; } +void +loadRandomOrbits(GameState* gs, + RenderState* rs, + const u32 count, + const GravBody& body, + RenderGroup* rg) +{ + assert(gs->num_orbits + count < DEFAULT_MAX_ORBITS); + srand(1); // NOTE: use the same seed every time + const double max_semi_major_axis = 50000; + const double min_semi_major_axis = 20000; + const double semi_major_axis_range = max_semi_major_axis - min_semi_major_axis; + const double max_eccentricity = 0.7; + const double max_nu = 2 * M_PI; + + for (u32 i = 0; i < count; i++) { + double semi_major_axis = fmod(fabs((double) rand()), semi_major_axis_range) + min_semi_major_axis; + double eccentricity = max_eccentricity * rand() / RAND_MAX; + double nu = max_nu * rand() / RAND_MAX; + //double omega = 2 * M_PI * rand() / RAND_MAX; + double omega = 0; + + GameOrbit* gorb = loadOrbit(gs, rs, body, + orbitInit(semi_major_axis, eccentricity, 0, 0, omega, nu), + rg, "???"); + + addManeuver(gs, gorb, ImpulseType::CIRCULARIZE_LOWERING); + } +} + bool loadScene(GameState* gs, RenderState* rs) { @@ -256,7 +288,7 @@ loadScene(GameState* gs, RenderState* rs) // TODO: streamline the boilerplate in init_X_Entity functions ShaderProgram* shader = getShaderByName("colored_vertices", rs->gl_ctx); RenderGroup* rg = getFreeRenderGroup(rs); - initRenderGroup(rg, rs->rg_arena, shader, 256, "manual mesh group"); + initRenderGroup(rg, rs->rg_arena, shader, 10000, "manual mesh group"); gs->coord_overlay = addCoordinateOverlay(rs); @@ -267,11 +299,14 @@ loadScene(GameState* gs, RenderState* rs) GameOrbit* go_2 = loadOrbit(gs, rs, body, el2, rg, "sat_02"); double v_transfer = orbitGetTransferVelocity(go_2->system, el1); addManeuver(gs, go_2, ImpulseType::PROGRADE, DEG2RAD(45), v_transfer); - addManeuver(gs, go_2, ImpulseType::CIRCULARIZE_LOWERING, DEG2RAD(0)); + addManeuver(gs, go_2, ImpulseType::CIRCULARIZE_LOWERING); // NOTE: pre-select an orbit for testing selectOrbit(gs, go_2); + // NOTE: add more orbits with maneuvers to try and provoke a failure + loadRandomOrbits(gs, rs, 1000, body, rg); + return true; } diff --git a/src/orbits.cpp b/src/orbits.cpp index 465080c..ad5a6f2 100644 --- a/src/orbits.cpp +++ b/src/orbits.cpp @@ -80,6 +80,8 @@ orbitGetElementsFromStateVectors(glm::dvec3 r, glm::dvec3 v, double mu) double r_mag = orbitGetVectorMagnitude(r); double v_mag = orbitGetVectorMagnitude(v); double epsilon = orbitGetSpecificEnergyFromStateVectors(r_mag, v_mag, mu); + // TODO: orbits other than ellipses + assert(epsilon < 0); glm::dvec3 ecc_v = orbitGetEccentricityVector(r, v, mu); el.a = orbitGetSemiMajorAxis(epsilon, mu); @@ -109,6 +111,8 @@ orbitGetElementsFromStateVectors(glm::dvec3 r, glm::dvec3 v, double mu) if (ecc_v.z < 0) el.omega = 2 * M_PI - el.omega; // quadrant check } + // FIXME: I think this is the smoking gun for the source of all the nan + // position and velocity components if (el.e == 0) { el.nu = 0; } else {