Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Reading Past The End Of Buffer - Small network list with no indication of why

Discussion in 'Netcode for GameObjects' started by Hines94, Sep 17, 2022.

  1. Hines94

    Hines94

    Joined:
    Feb 15, 2020
    Posts:
    19
    Hi,

    I have a very small network list with just a couple of instances of a struct FloatStatValue (below) inside. I am getting a "Reading Past The End Of Buffer" error (below) on my client every time the data is sent. All indications about this issue indicate that it is related to the size but my list has just a few items in it.

    Unity Version: 2021.3.10
    Netcode Version: Version 1.0.2 (latest)

    Network List:
    Code (CSharp):
    1.  
    2.         public NetworkList<FloatStatValue> Server_FloatValues;
    3.         private void Awake()
    4.         {
    5.             Server_FloatValues = new NetworkList<FloatStatValue>();
    6.         }
    7.  
    My struct:

    Code (CSharp):
    1.     [System.Serializable]
    2.     //Represents a random stat. A simple stat which could be anything.
    3.     public struct FloatStatValue : INetworkSerializable, IEquatable<FloatStatValue>, ISerializationCallbackReceiver
    4.     {
    5.         //If for example we want a nice inspector for our base
    6.         [HideInInspector()]
    7.         public bool NoChangeType;
    8.         //A uuid we can use to update a stat or remove it
    9.         [ReadOnly()]
    10.         public Guid UUID;
    11.  
    12.         [HideIf("NoChangeType",true)]
    13.         public StatType StatType;
    14.         [HideIf("NoChangeType", true)]
    15.         public StatAffix AffixType;
    16.         public float Value;
    17.  
    18.         public FloatStatValue(StatType ST, StatAffix SA,float Val, bool bNoChangeType = false)
    19.         {
    20.             UUID = System.Guid.NewGuid();
    21.             StatType = ST;
    22.             AffixType = SA;
    23.             Value = Val;
    24.             NoChangeType = bNoChangeType;
    25.         }
    26.  
    27.         public bool Equals(FloatStatValue other)
    28.         {
    29.             if(other.StatType != StatType) { return false; }
    30.             if (other.AffixType != AffixType) { return false; }
    31.             if (other.Value != Value) { return false; }
    32.             return true;
    33.         }
    34.  
    35.         public int GetValueAsInt()
    36.         {
    37.             return Mathf.RoundToInt(Value);
    38.         }
    39.  
    40.         public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    41.         {
    42.             serializer.SerializeValue(ref Value);
    43.             serializer.SerializeValue(ref AffixType);
    44.             serializer.SerializeValue(ref StatType);
    45.         }
    46.  
    47.         public void OnAfterDeserialize()
    48.         {
    49.             return;
    50.         }
    51.  
    52.         public void OnBeforeSerialize()
    53.         {
    54.             if(UUID == Guid.Empty) { UUID = Guid.NewGuid(); }
    55.         }
    56.     }

    Error:
    OverflowException: Reading past the end of the buffer
    Unity.Netcode.FastBufferReader.ReadBytesSafe (System.Byte* value, System.Int32 size, System.Int32 offset) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Serialization/FastBufferReader.cs:666)
    Unity.Netcode.FastBufferReader.ReadUnmanagedSafe[T] (T& value) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Serialization/FastBufferReader.cs:720)
    Unity.Netcode.FastBufferReader.ReadValueSafe[T] (T& value, Unity.Netcode.FastBufferWriter+ForPrimitives unused) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Serialization/FastBufferReader.cs:867)
    Unity.Netcode.NetworkVariableDeltaMessage.Handle (Unity.Netcode.NetworkContext& context) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs:159)
    Unity.Netcode.MessagingSystem.ReceiveMessage[T] (Unity.Netcode.FastBufferReader reader, Unity.Netcode.NetworkContext& context, Unity.Netcode.MessagingSystem system) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Messaging/MessagingSystem.cs:457)
    Unity.Netcode.MessagingSystem.HandleMessage (Unity.Netcode.MessageHeader& header, Unity.Netcode.FastBufferReader reader, System.UInt64 senderId, System.Single timestamp, System.Int32 serializedHeaderSize) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Messaging/MessagingSystem.cs:387)
    UnityEngine.Debug:LogException(Exception)
    Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single, Int32) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Messaging/MessagingSystem.cs:391)
    Unity.Netcode.MessagingSystem:processIncomingMessageQueue() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Messaging/MessagingSystem.cs:407)
    Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Core/NetworkManager.cs:1541)
    Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Core/NetworkManager.cs:1473)
    Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Core/NetworkUpdateLoop.cs:185)
    Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.2/Runtime/Core/NetworkUpdateLoop.cs:208)
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    653
    I tried to reproduce the issue but didn't get any errors, the problem may not be with the struct itself. I'd suggest creating a test project and see if you can reproduce the issue there.
     
    Hines94 likes this.
  3. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    457
    I also wonder if this is a regression, you could try with a previous package version of NGO if possible.