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

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

7.8k Downloads

C# ActiveVessel throws System.ArgumentNullException

Grille opened this issue · 2 comments

commented

What happened?

When using the ActiveVessel property while no vehicle is active; this exception is thrown:

System.ArgumentNullException: 'Value cannot be null.
Parameter name: vessel
Server stack trace: 
  at KRPC.SpaceCenter.Services.Vessel..ctor (Vessel vessel) [0x00012] in <d8566df5220a4070afa44bd2ecc53aa8>:0 

I’m not sure if this is what’s supposed to happen? If that’s excepected I would have expected an more descriptive error message. Also an alternative bool TryGetActiveVessel(out Vessel vessel) method would be nice then.

Also, once it’s clear what this is, I might be willing to try to contribute myself ^^

How can someone else reproduce it?

Use ActiveVessel while none is active in game.

What is your environment?

c#
krpc 0.5.4

Anything else we need to know?

No response

commented

This issue stems from a missing Nullable = true for [KRPCProperty] here as well as a missing null check for FlightGlobals.ActiveVessel in the property's getter. This is a bug in kRPC and thus the error message isn't the greatest but honestly I'm not sure how it could be made better.

If that's enough for you to make the PR (and you still wish to), go ahead. If not, I'll do so.

commented

Your proposed fixes sound good to me.

Once those changes are made, the exception won't occur, so no need for a "better error message'. Error messages like that shouldn't usually appear to the end user.