Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log spam when editing nodes #3

Closed
HebaruSan opened this issue Mar 11, 2021 · 8 comments
Closed

Log spam when editing nodes #3

HebaruSan opened this issue Mar 11, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@HebaruSan
Copy link
Owner

HebaruSan commented Mar 11, 2021

Background

PlanningNode version: 0.1.2

KSP version: 1.11

Problem

LOTS of these messages (a user reported 1 MB/s; I saw a 13 MB total log after testing) are filed to the log by stock code some of the time while the node editor is active:

[LOG 19:17:05.807] dT is NaN! tA: NaN, E: NaN, M: NaN, T: NaN
  at System.Environment.get_StackTrace () [0x00000] in <ad04dee02e7e4a85a1299c7ee81c79f6>:0 
  at Orbit.GetDTforTrueAnomaly (System.Double tA, System.Double wrapAfterSeconds) [0x00000] in <2afc64dea36946459d4707808bdac511>:0 
  at Trajectory.UpdateFromOrbit (Orbit orbit, System.Int32 sampleCount) [0x00000] in <2afc64dea36946459d4707808bdac511>:0 
  at PatchRendering.UpdatePR () [0x00000] in <2afc64dea36946459d4707808bdac511>:0 
  at PatchedConicRenderer.LateUpdate () [0x00000] in <2afc64dea36946459d4707808bdac511>:0 

It isn't consistent from what I have been able to gather; sometimes it happens, sometimes not.

Cause

The message says that dT, tA, E, M, and T are all NaN, which suggests to me that those are orbital elements of an orbit that hasn't been initialized. Since the orbit is a parameter to Trajectory.UpdateFromOrbit, it must be originating somewhere in the PatchRendering.UpdatePR call. So maybe there's a render patch that doesn't have a valid orbit? If we could find that patch, maybe we could set activePatch = false to prevent it from being checked like this. Don't know when that should be done, though. Before PatchedConicRenderer.LateUpdate, I guess.

@HebaruSan HebaruSan added the bug Something isn't working label Mar 11, 2021
@HebaruSan HebaruSan self-assigned this Mar 11, 2021
@HebaruSan HebaruSan pinned this issue Mar 11, 2021
@HebaruSan
Copy link
Owner Author

HebaruSan commented Mar 11, 2021

If we could find that patch, maybe we could set activePatch = false to prevent it from being checked like this.

Tried this, didn't help at all. ☹️

@HebaruSan
Copy link
Owner Author

Inserting extra markers at Update and LateUpdate, I count 96 messages per frame. PatchedConicRenderer.patchSamples is 48, so this suggests there are two patches somewhere with NaN elements that the renderer is trying to process. (But the Orbit constructor I'm using fully initializes everything, so these mystery orbits are coming from somewhere else.)

The messages only seem to start up once you drag one of the handles; several seconds elapse in the log between the exception that marks the opening of the editor and the start of the log spam. So maybe they're generated when the solver updates its flight plan? But why only here and not when stock does it? To be continued...

Tried removing OrbitTargeter completely; no effect.

@HebaruSan
Copy link
Owner Author

HebaruSan commented Mar 13, 2021

I think this is related to the fix from 8669492; the flight plan ends up with a NaN orbit because the starting body gets in the way of the dummy vessel's maneuvers.

Tried looping over our solver's flight plan in OnGizmoUpdated, Update, LateUpdate, and FixedUpdate and disabling and/or removing NaN orbits. The log spam continued (at a reduced rate? hard to tell). It looks like the different stock components sometimes generate the bad data and then react to it with log spam without my code having a chance to step in and clean up. It's particularly tricky because the flight plan is regenerated from scratch every time, so fixing corrupted orbits only helps if you get to it early.

Tried using the celestial body's OrbitDriver instead of making our own (by generating all components with editingNode.origin.gameObject.AddComponent<>), since the solver skips the same orbit for purposes of finding encounters, and the game immediately froze up completely.

@HebaruSan
Copy link
Owner Author

Seems to mostly afflict newly created orbits with 0 dV, presumably since the post-maneuver patch then intersects the original orbit a whole lot. Editing my old saved nodes with real transfers doesn't produce spam (as much?).

Maybe we could create a "delta V dead zone," where if you get too close to 0, we automatically add some vector to avoid self-intersections? I could imagine defaulting a new node to 100 m/s prograde, and if you increase that, it would be fine; if you decrease it, then we jump you to -100 m/s prograde (=100 m/s retrograde), so you can still set up both inwards and outwards transfers, just nothing too close to your starting body's orbit.

Could even attempt to trigger that behavior by searching the flight plan for NaN orbits.

Or maybe we could increase and decrease the number of allowed flight node patches based on whether real encounters have been found? Start with 2 to account for the initial orbit and one maneuver, and then if we find the patch ending in an encounter, make sure it's real, and if so, increase the limit?

@HebaruSan
Copy link
Owner Author

Tried setting up a 100 m/s dead zone and then 500 m/s. Log still spammed.

@HebaruSan
Copy link
Owner Author

I guess as a last resort, I could try to write a replacement for PatchedConicsSolver that handles this scenario without creating NaN orbits. The PatchedConics class and its important functions are public. However, other objects reference the solver by type, such as the maneuver node gizmo, so it would have to inherit.

@HebaruSan
Copy link
Owner Author

HebaruSan commented Mar 13, 2021

Or, PatchedConics.CheckEncounter is a static delegate reference to the real implementation; maybe I can override that to avoid NaN orbits?

@HebaruSan
Copy link
Owner Author

Fixed in e9f6809.

@HebaruSan HebaruSan unpinned this issue Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant