Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastBufferReader does not respect ArraySegment.Offset #2885

Open
Risord opened this issue Apr 17, 2024 · 1 comment
Open

FastBufferReader does not respect ArraySegment.Offset #2885

Risord opened this issue Apr 17, 2024 · 1 comment
Assignees
Labels
priority:high stat:imported Issue is tracked internally at Unity type:bug Bug Report

Comments

@Risord
Copy link

Risord commented Apr 17, 2024

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 Risord added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Apr 17, 2024
@fluong6 fluong6 added priority:high stat:import and removed stat:awaiting triage Status - Awaiting triage from the Netcode team. labels Apr 22, 2024
@NoelStephensUnity
Copy link
Collaborator

@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);

@fluong6 fluong6 added stat:imported Issue is tracked internally at Unity and removed stat:import labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:high stat:imported Issue is tracked internally at Unity type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

4 participants