kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

Orbit.next_orbit will Block the program completly when first called (in a python stream) and not existing.

JoRadiver opened this issue ยท 1 comments

commented

When vessel.orbit.next_orbit is in a stream, the first call will completly block the program until it is no longer None:
Test this code:

import krpc
import time
conn = krpc.connect()
vessel = conn.space_center.active_vessel
refframe = vessel.orbit.body.reference_frame
next_orbit = conn.add_stream(getattr, vessel.orbit, "next_orbit")
while True:
    print(next_orbit())
    time.sleep(3)

When you start it while your vessel has no next_orbit, it will just block until an next_orbit exists.
It will then work as inteded, even return None when there is no next Orbit agian.
It will also block whenever you switch to a new Vessel, which does not have a next_orbit.
Only when it is from the start, it will block.

It does not throw an exception, it just stops the program.
Seems to only be that code in Orbit.cs line 298

/// <summary>
/// If the object is going to change sphere of influence in the future, returns the new
/// orbit after the change. Otherwise returns <c>null</c>.
/// </summary>
[KRPCProperty (Nullable = true)]
public Orbit NextOrbit {
      get { return (double.IsNaN (TimeToSOIChange)) ? null : new Orbit (InternalOrbit.nextPatch); }
}

Dont't know c# really yet, can't see any problems here.

commented

Apologies for the very slow response...

There was a bug on server side. It doesn't send a stream update if the first value of the stream is null, which causes the client to sit there waiting for the first update (as a stream is supposed to be guaranteed to send an update immediately after creation so that the client can initialize the value of the stream). A fix for this will be released in the next version of the mod.