Search Unity

"NetworkReader:ReadByte out of range:NetBuf sz:0 pos:0" Error in 2020.1

Discussion in 'Multiplayer' started by PhoenixAdvanced, Jul 24, 2020.

  1. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hello,

    I am in the process of porting to 2020.1 from 2019.3 (I need some of the new 2020 features for my project).

    Everything seems to have gone fine so far, except for this error (Log dump Below).

    I am using UNET, I haven't migrated away yet.

    I have converted both my server and client apps to 2020.1, both of them run with no issues other than this one.

    My Old (2019.3) server app works fine with my new (2020.1) client app, so I am guessing that the issue occurs on the server?

    The only change I made was when I ported I ran into an error about "Deterministic compilation failed", which I solved by updating the HLAPI version to 1.0.6 from 1.0.4. Could this have caused the error?

    This issue occurs in the console several times, and prevents communication with the server. The line that it complains about (In mainserver.cs) is:

    persistentobjectinfomsg msg = netMsg.ReadMessage<persistentobjectinfomsg>();

    All of the readbyte errors occur on a "readmessage" line.

    I have done some searching, and I have already tried adding "seekzero" before readmessage, and I have tried using try/catch blocks, neither of these solutions has worked.

    Can anyone shed any light on this?

    Thanks!


    Code (CSharp):
    1. IndexOutOfRangeException: NetworkReader:ReadByte out of range:NetBuf sz:0 pos:0
    2. UnityEngine.Networking.NetBuffer.ReadByte () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkBuffer.cs:38)
    3. UnityEngine.Networking.NetworkReader.ReadByte () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkReader.cs:260)
    4. UnityEngine.Networking.NetworkReader.ReadPackedUInt32 () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkReader.cs:146)
    5. persistentobjectinfomsg.Deserialize (UnityEngine.Networking.NetworkReader reader) (at <2dc18888417d44478793688727add9cf>:0)
    6. UnityEngine.Networking.NetworkMessage.ReadMessage[TMsg] () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/UNetwork.cs:330)
    7. mainserver.loadnavobject (UnityEngine.Networking.NetworkMessage netMsg) (at Assets/Scripts/SERVER/mainserver.cs:1932)
    8. UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, System.Int32 receivedSize, System.Int32 channelId) (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkConnection.cs:733)
    9. UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, System.Int32 receivedSize, System.Int32 channelId) (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkConnection.cs:670)
    10. UnityEngine.Networking.NetworkConnection.TransportReceive (System.Byte[] bytes, System.Int32 numBytes, System.Int32 channelId) (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkConnection.cs:896)
    11. UnityEngine.Networking.NetworkClient.Update () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkClient.cs:991)
    12. UnityEngine.Networking.NetworkClient.UpdateClients () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkClient.cs:1262)
    13. UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkIdentity.cs:1245)
    14. UnityEngine.Networking.NetworkCallbacks.LateUpdate () (at Library/PackageCache/com.unity.multiplayer-hlapi@1.0.6/Runtime/NetworkCallbacks.cs:11)
    15.  
    16.  
     
  2. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    I think this may have been a simple case of an uninitialised variable in my server message. I don't know why this worked in 2019.3, but when I made sure all variables were initialised, it seems to work ok in 2020.1.
     
  3. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Scratch that.

    This issue still occurs, but the behaviour is quite strange.

    It seems to occur intermittently, then disappear and not occur again until I change something on the server, or connect to a different server. i can't seem to figure out what is causing this.

    It is always coming from one of my messages, but it seems to happen with different ones, semi-randomly?
     
  4. Majedev

    Majedev

    Joined:
    Jun 25, 2017
    Posts:
    7
    Ran into the same thing after I migrated my project to 2020.3.0f1. Deleting Library/PackageCache/com.unity.multiplayer-hlapi@1.0.8 directory resolved the issue for me.

    * update: I reverted my project back to 2019.4.22f1, as 2020.3.0f1 seemed slow/buggy
     
    Last edited: Mar 11, 2021
  5. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    I think I did that too at one point. I eventually fixed it by updating the hlapi version, I had been using a slightly older version without realising it. It was either the update or deleting the library directory that fixed it.
     
  6. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    This is a UNET bug that was never fixed.
    It's actually the reason why we started the fork (now Mirror).