com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
FastBufferReader does not respect ArraySegment.Offset
Description
var bytes = new byte[] { 0, 1, 2, 3 };
var segment = new ArraySegment<byte>(bytes, 1, 3);
var reader = new Unity.Netcode.FastBufferReader(segment, Unity.Collections.Allocator.Temp);
Debug.Log(string.Join(',', segment.ToArray())); // => 1,2,3
Debug.Log(string.Join(',', reader.ToArray())); // => 0,1,2
Expected Outcome
Both prints output: 1,2,3
Environment
- OS: Windows 11
- Unity Version: 2022.3.24
- Netcode Version: 1.8.1
@Risord Yeah, this indeed does look like it does not honor the ArraySegment and a fix would be for us to create a new constructor that does not include the length or offset parameters in order to be 100% sure of the intended usage.
For now, the work around would be to add the offset in the constuctor:
var bytes = new byte[] { 0, 1, 2, 3 };
var segment = new System.ArraySegment<byte>(bytes, 1, 3);
var reader = new Unity.Netcode.FastBufferReader(segment, Unity.Collections.Allocator.Temp, offset: 1);