[Lidgren] Out of range after fews seconds

Hello,

I created 2 entities on the server, a player and a cube.
These 2 entities communicate their position at the moment whenever it changes.

The problem is that I get busy, when I move one and after a few seconds, the server crash for no apparent reason.

I tried to move an entity without the other being present, it works correctly.
When I display a debug message in the client code that displays the entity ID, everything works fine …

Your message:
"An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll
Additional Information: The index was out of bounds. It must not be negative and must be less than the size of the collection. "

CLIENT

void Update()
{
        NetOutgoingMessage outMsg = NetworkManager.Instance.client.CreateMessage();
        outMsg.Write((int)PackType.ENTITY_POSITION);
        outMsg.Write(networkActor.ID);
        outMsg.Write(transform.position.x);
        outMsg.Write(transform.position.y);
        outMsg.Write(transform.position.z);
       NetworkManager.Instance.client.SendMessage(outMsg, NetDeliveryMethod.UnreliableSequenced);
}

SERVER

PackType type = (PackType)inMsg.ReadInt32();
ID = inMsg.ReadInt32();
PositionX = inMsg.ReadFloat();
PositionY = inMsg.ReadFloat(); // BUG
PositionZ = inMsg.ReadFloat();

Thank you for your help.

@ , your server code is not reading the same types that are being sent by the client:

Client sends:
int32
int32 (assumed, not shown but it is networkActor.ID)
float
float
float

Server code reads:
int32
float
float
float

This will definitely cause a problem. The decoded data on the sever will be garbage and crashing wouldn’t be a surprise.

Sorry, this code exist but i’ve forget to write this :

SERVER

PackType type = (PackType)inMsg.ReadInt32();

*Topic edited