MLAPI.Relay icon indicating copy to clipboard operation
MLAPI.Relay copied to clipboard

Out of bounds exception

Open genaray opened this issue 4 years ago • 2 comments

Was already posted on the discord... theres a weird exception going on when using the relay... It happens completly randomly but is game breaking. https://media.discordapp.net/attachments/563033158480691211/803724646826377226/unknown.png?width=1440&height=178

genaray avatar Jan 26 '21 20:01 genaray

We're seeing this as well, and also inconsistently.

timmeh4242 avatar Apr 22 '21 07:04 timmeh4242

Hi All,

I'm not getting this issue any more after doing the below changes in the Send function.

Note: I'm not sure if this is the correct way to fix this issue but it worked for me.

public bool Send (int hostId, int connectionId, int channelId, byte [] buffer, int size, out byte error)
{
    if (!Enabled) return NetworkTransport.Send (hostId, connectionId, channelId, buffer, size, out error);

    ++size;

    if (!isClient)
    {
        size += 8;

        // ********************************************************
        // Birla: Resizing 'buffer' array as 'buffer.Length < size'
        // ********************************************************
        if (buffer.Length < size)
        {
            Debug.LogErrorFormat ("<color=cyan>Resizing 'buffer' array as buffer.Length ({0}) < size ({1})</color>", buffer.Length, size);

            byte [] tempBuffer = new byte [size];

            Buffer.BlockCopy (buffer, 0, tempBuffer, 0, buffer.Length);

            buffer = tempBuffer;
        }
        // ********************************************************

        int connectionIdOffset = size - 9;

        for (byte i = 0; i < sizeof (ulong); i++) buffer [connectionIdOffset + i] = ((byte) ((ulong) connectionId >> (i * 8)));
    }

    buffer [size - 1] = (byte) MessageType.Data;

    return NetworkTransport.Send (hostId, relayConnectionId, channelId, buffer, size, out error);
}

ajaybirla avatar Apr 30 '21 06:04 ajaybirla