Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed
- Fixed server side issue where, depending upon component ordering, some NetworkBehaviour components might not have their OnNetworkDespawn method invoked if the client side disconnected. (#2323)
- Fixed a case where data corruption could occur when using UnityTransport when reaching a certain level of send throughput. (#2332)

- Fixed an issue in `UnityTransport` where an exception would be thrown if starting a Relay host/server on WebGL. This exception should only be thrown if using direct connections (where WebGL can't act as a host/server). (#2321)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
{
writer.WriteInt(messageLength);

var messageOffset = HeadIndex + reader.GetBytesRead();
var messageOffset = reader.GetBytesRead();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look above here, there's readerOffset = HeadIndex. This was changed in #2224 from readerOffset = 0 because reader was changed from being a slice of m_data to containing all of m_data and reading from that offset. The return value of GetBytesRead() here already includes HeadIndex, so this results in HeadIndex being applied twice when calculating messageOffset.

When HeadIndex is 0 that has no effect, but when the queue gets filled more, it starts resulting in things being skipped over, data being corrupted, and - sometimes - data from completely outside the stream (i.e., garbage data) being copied into the stream.

WriteBytes(ref writer, (byte*)m_Data.GetUnsafePtr() + messageOffset, messageLength);

writerAvailable -= sizeof(int) + messageLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ public void BatchedSendQueue_FillWriterWithMessages_PartialPushedMessages()
var writer = new DataStreamWriter(data);
Assert.AreEqual(messageLength, q.FillWriterWithMessages(ref writer));
AssertIsTestMessage(data);

q.Consume(messageLength);

writer = new DataStreamWriter(data);
Assert.AreEqual(messageLength, q.FillWriterWithMessages(ref writer));
AssertIsTestMessage(data);
}

[Test]
Expand Down