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

Tried to push NaN into the stack #2695

Closed
astappiev opened this issue Apr 28, 2020 · 7 comments
Closed

Tried to push NaN into the stack #2695

astappiev opened this issue Apr 28, 2020 · 7 comments
Labels
invalid Devs do not agree the problem is a problem, or it's a misunderstanding.

Comments

@astappiev
Copy link

astappiev commented Apr 28, 2020

Hi,

I'm getting this error when trying to access nextnode:deltav:mag.

I have such code

local nn is nextnode.

print nn.
print nn:deltav.
print nn:deltav:mag.

Which leads to the following results (the first run it works fine, but another it throws the error).

image

This error happens each second time I run my scenario, and the node is not empty, but deltav vector is empty for unknown for me reasons.

I tried to reproduce it, like below, but it works.

SET NN TO NODE(time:seconds + 1580.85838020034, 0, 0, -176.422379997147).
ADD NN.

PRINT nextnode.
PRINT nextnode:deltav.

Any idea?

@nuggreat
Copy link

nuggreat commented Apr 28, 2020

Would need more of the code to try to find the specific cause of the problem. But it might be something like you are saving the reference to the first node and then once execute and remove the first node you don't update the reference to the 2nd node when said node is made.

@hany
Copy link

hany commented Apr 28, 2020

I’m running into the exact same issue (likely using the exact same script). The code being run is:

https://github.com/xeger/kos-ramp/blob/master/ramp/landvac.ks#L126-L132

I run the same script (from a quicksave point) over and over, and about 50% of the time I get this error. Trying to dump the contents of the node variables shows everything is in order until you try to read the value of deltav.

@nuggreat
Copy link

Does anything show up in the KSP log files when the script fails?
Do you have any other mods that might be doing things to maneuver nodes as only happening some of the time sounds kind of like a race condition between mods.

@hany
Copy link

hany commented Apr 29, 2020

Yes, there is quite a bit in the logs when the issue happens:

[LOG 14:00:38.626] 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 <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConics._CalculatePatch (Orbit p, Orbit nextPatch, System.Double startEpoch, PatchedConics+SolverParameters pars, CelestialBody targetBody) [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConicSolver.CheckNextManeuver (System.Int32 nodeIdx, Orbit nodePatch, System.Int32 patchesAhead) [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConicSolver.CheckNextManeuver (System.Int32 nodeIdx, Orbit nodePatch, System.Int32 patchesAhead) [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConicSolver.UpdateFlightPlan () [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at kOS.Suffixed.Node.AddToVessel (Vessel v) [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Function.FunctionAddNode.Execute (kOS.SharedObjects shared) [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Function.FunctionBase.Execute (kOS.Safe.SafeSharedObjects shared) [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Safe.Function.FunctionManager.CallFunction (System.String functionName) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.CallBuiltinFunction (System.String functionName) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Compilation.OpcodeCall.StaticExecute (kOS.Safe.Execution.ICpu cpu, System.Boolean direct, System.Object destination, System.Boolean calledFromKOSDelegateCall) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Compilation.OpcodeCall.Execute (kOS.Safe.Execution.ICpu cpu) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.ExecuteInstruction (kOS.Safe.Execution.ProgramContext context, System.Boolean doProfiling) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.ContinueExecution (System.Boolean doProfiling) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.KOSFixedUpdate (System.Double deltaTime) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.UpdateHandler.UpdateFixedObservers (System.Double deltaTime) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Module.kOSProcessor.UpdateFixedObservers () [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Module.kOSProcessor.FixedUpdate () [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
[LOG 14:00:38.627] 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 <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConics._CalculatePatch (Orbit p, Orbit nextPatch, System.Double startEpoch, PatchedConics+SolverParameters pars, CelestialBody targetBody) [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConicSolver.CheckNextManeuver (System.Int32 nodeIdx, Orbit nodePatch, System.Int32 patchesAhead) [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConicSolver.CheckNextManeuver (System.Int32 nodeIdx, Orbit nodePatch, System.Int32 patchesAhead) [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at PatchedConicSolver.UpdateFlightPlan () [0x00000] in <48dcb08e2e1542e2af1286b02d2eb072>:0 
  at kOS.Suffixed.Node.AddToVessel (Vessel v) [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Function.FunctionAddNode.Execute (kOS.SharedObjects shared) [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Function.FunctionBase.Execute (kOS.Safe.SafeSharedObjects shared) [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Safe.Function.FunctionManager.CallFunction (System.String functionName) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.CallBuiltinFunction (System.String functionName) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Compilation.OpcodeCall.StaticExecute (kOS.Safe.Execution.ICpu cpu, System.Boolean direct, System.Object destination, System.Boolean calledFromKOSDelegateCall) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Compilation.OpcodeCall.Execute (kOS.Safe.Execution.ICpu cpu) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.ExecuteInstruction (kOS.Safe.Execution.ProgramContext context, System.Boolean doProfiling) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.ContinueExecution (System.Boolean doProfiling) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.KOSFixedUpdate (System.Double deltaTime) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.UpdateHandler.UpdateFixedObservers (System.Double deltaTime) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Module.kOSProcessor.UpdateFixedObservers () [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
  at kOS.Module.kOSProcessor.FixedUpdate () [0x00000] in <64b1c76e033842d2bd7fb92c02239116>:0 
[LOG 14:00:39.897] [ContractParameter]:  on Contract Position satellite in a polar orbit of Minmus. set to Complete.
[LOG 14:00:39.977] kOS: FlightControlManager: ToggleFlyByWire: steering True
[LOG 14:00:39.980] kOS: At 1:/node.ks, line 48
if resetBurnTime set burnTime to burnTimeForDv(nn:deltav:mag).
                                               ^
Called from 1:/landvac.ks, line 141
	run node.
     ^
Called from 1:/harvestland, line 16
run landvac("TARG").
            ^

[LOG 14:00:39.980] System.Exception: Tried to push NaN into the stack.
  at kOS.Safe.Execution.Stack.ThrowIfInvalid (System.Object item) [0x00044] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.Stack.PushArgument (System.Object item) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.PushArgumentStack (System.Object item) [0x00000] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Compilation.OpcodeGetMember.Execute (kOS.Safe.Execution.ICpu cpu) [0x00077] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.ExecuteInstruction (kOS.Safe.Execution.ProgramContext context, System.Boolean doProfiling) [0x001e5] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.ContinueExecution (System.Boolean doProfiling) [0x00030] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
  at kOS.Safe.Execution.CPU.KOSFixedUpdate (System.Double deltaTime) [0x000b0] in <1f05d5b75d1c42729d0e0281470dcabd>:0 
[LOG 14:00:39.981] Code Fragment
File                 Line:Col IP   label   opcode operand
====                 ====:=== ==== ================================  
1:/node.ks             44:1   4244 @4204   push 80 
1:/node.ks             44:1   4245 @4205   addtrigger, Pri 30  
1:/node.ks             44:1   4246 @4206   push _KOSArgMarker_ 
1:/node.ks             44:1   4247 @4207   push steering 
1:/node.ks             44:1   4248 @4208   push True 
1:/node.ks             44:1   4249 @4209   call toggleflybywire() 
1:/node.ks             44:1   4250 @4210   pop 
1:/node.ks             47:24  4251 @4211   push $burntime 
1:/node.ks             47:35  4252 @4212   push 0 
1:/node.ks             47:33  4253 @4213   eq 
1:/node.ks             47:33  4254 @4214   storelocal $resetburntime 
1:/node.ks             48:4   4255 @4215   push $resetburntime 
1:/node.ks             48:4   4256 @4216   br.false +7 
1:/node.ks             48:47  4257 @4217   push _KOSArgMarker_ 
1:/node.ks             48:48  4258 @4218   push $nn 
1:/node.ks             48:48  4259 @4219   getmember deltav 
1:/node.ks             48:48  4260 @4220   getmember mag <<--INSTRUCTION POINTER--
1:/node.ks             48:48  4261 @4221   call $burntimefordv* 
1:/node.ks             48:48  4262 @4222   store $burntime 
1:/node.ks             49:13  4263 @4223   push $burntime 
1:/node.ks             49:24  4264 @4224   push 2 
1:/node.ks             49:22  4265 @4225   div 
1:/node.ks             49:22  4266 @4226   storelocal $dt 
1:/node.ks             51:19  4267 @4227   push 2 
1:/node.ks             51:19  4268 @4228   storelocal $warploop 
1:/node.ks             52:7   4269 @4229   push False 
1:/node.ks             52:7   4270 @4230   not 
1:/node.ks             52:7   4271 @4231   br.false +165 
1:/node.ks             52:13  4272 @4232   pushscope 161 157 
1:/node.ks             57:7   4273 @4233   push 0 
1:/node.ks             57:7   4274 @4234   wait 
1:/node.ks             58:18  4275 @4235   push False 
1:/node.ks             58:18  4276 @4236   storelocal $warped 

[LOG 14:00:39.982] kOS: Argument Stack dump:
Argument Stack: count = 7
006 SP-> _KOSArgMarker_ (type: KOSArgMarkerType)

005      _KOSArgMarker_ (type: KOSArgMarkerType)

004      _KOSArgMarker_ (type: KOSArgMarkerType)

003      _KOSArgMarker_ (type: KOSArgMarkerType)

002      _KOSArgMarker_ (type: KOSArgMarkerType)

001      _KOSArgMarker_ (type: KOSArgMarkerType)

000      0 (type: Int32)

Scope Stack: count = 11
010 SP-> kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=157, ParentScopeId=0, IsClosure=True
            local var $nodecreator is Variable with value = $nodecreator
            local var $burntime is Variable with value = $burntime
            local var $sstate is Variable with value = $sstate
            local var $rstate is Variable with value = $rstate
            local var $nn is Variable with value = $nn
            local var $resetburntime is Variable with value = $resetburntime
009      SubroutineContext: {CameFromInstPtr 22, TriggerPointer } (type: SubroutineContext)

008      kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=-999, ParentScopeId=0, IsClosure=False
            local var $runonce is Variable with value = $runonce
            local var $filename is Variable with value = $filename
            local var $entrypoint is Variable with value = $entrypoint
007      SubroutineContext: {CameFromInstPtr 600, TriggerPointer } (type: SubroutineContext)

006      kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=3, ParentScopeId=2, IsClosure=False
            local var $deorbitrad is Variable with value = $deorbitrad
            local var $r1 is Variable with value = $r1
            local var $r2 is Variable with value = $r2
            local var $pt is Variable with value = $pt
            local var $sp is Variable with value = $sp
            local var $deorbittraveltime is Variable with value = $deorbittraveltime
            local var $phi is Variable with value = $phi
            local var $inctraveltime is Variable with value = $inctraveltime
            local var $phiincmaneuver is Variable with value = $phiincmaneuver
            local var $vel is Variable with value = $vel
            local var $inc is Variable with value = $inc
            local var $totincdv is Variable with value = $totincdv
            local var $ndv is Variable with value = $ndv
            local var $pdv is Variable with value = $pdv
            local var $deorbit_dv is Variable with value = $deorbit_dv
            local var $nd is Variable with value = $nd
005      kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=2, ParentScopeId=0, IsClosure=False
            local var $landmode is Variable with value = $landmode
            local var $landlat is Variable with value = $landlat
            local var $landlng is Variable with value = $landlng
            local var $drawdebugvectors is Variable with value = $drawdebugvectors
004      SubroutineContext: {CameFromInstPtr 22, TriggerPointer } (type: SubroutineContext)

003      kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=-999, ParentScopeId=0, IsClosure=False
            local var $runonce is Variable with value = $runonce
            local var $filename is Variable with value = $filename
            local var $entrypoint is Variable with value = $entrypoint
002      SubroutineContext: {CameFromInstPtr 36, TriggerPointer } (type: SubroutineContext)

001      kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=1, ParentScopeId=0, IsClosure=False
000      kOS.Safe.Execution.VariableScope (type: VariableScope)

          ScopeId=1, ParentScopeId=0, IsClosure=False

[LOG 14:00:39.982] kOS: Popping context 2
[LOG 14:00:39.982] kOS: FlightControlManager: ToggleFlyByWire: steering False
[LOG 14:00:39.982] kOS: Removed Context File                 Line:Col IP   label   opcode operand
[LOG 14:00:39.982] kOS: Deleting 16 pointers and restoring 19 pointers
[LOG 14:00:39.982] kOS: New current context File                 Line:Col IP   label   opcode operand

I do have some mods, but actively running at the time, and nothing in this log stands out as interference from a mod AFAICT.

@nuggreat
Copy link

nuggreat commented Apr 29, 2020

Right just did some testing and I think this is a KSP bug that only happens when you try to create a maneuver that exactly counters the orbital velocity at that given point in time. The way it only happens some of the time makes me think the bug is caused by some race condition within KSP it's self.

I did discover a workaround for the bug and that was to modify the DV slightly I recommend dividing by 1.0001 as that is close enough to the original amount to work while also not an exact counter to the orbital velocity.

This is the code I used to replicate the bug. The first 6 lines are just cleanup from a previous run and set up for the current run, only the UNTIL RCS loop holds the code to generate the bug.

RCS OFF.
until not hasnode {
	wait 0.
	remove nextnode.
}
WAIT 0.
UNTIL RCS {
	local BreakingDeltaV to velocityat(ship, time:seconds + eta:periapsis):orbit:mag.
	local nd to node(time:seconds + eta:periapsis, 0, 0, -BreakingDeltaV).
	add nd.
	local ct is nd:deltav.
	print ct.
	print ct:mag.
	wait 0.
	remove nextnode.
}

Additional notes on reproduction: The craft running the script was in a mostly circular (eccentricity about 0.001) in an equatorial orbit. The script doesn't always thrown an error on the first run through hence why it is in a loop, hence why I suspect a race condition of some kind. IPU appeared to not affect reproduction.

@astappiev
Copy link
Author

Thanks, @nuggreat! Your workaround works fine.

In case someone will need to reproduce, I was using this save and code from the previous message I was able to reproduce the error every time I run it (in the first run of the loop).

astappiev added a commit to xeger/kos-ramp that referenced this issue Apr 29, 2020
Workaround proposed by @nuggreat is used.
See this issue for details KSP-KOS/KOS#2695
@Dunbaratu
Copy link
Member

The comments indicate this is not a bug in kOS but in KSP and there's not much we can do about it.

@Dunbaratu Dunbaratu added the invalid Devs do not agree the problem is a problem, or it's a misunderstanding. label Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Devs do not agree the problem is a problem, or it's a misunderstanding.
Projects
None yet
Development

No branches or pull requests

4 participants