From b7a45ac4fb9c614a514f7e8620d86de6dcc162cb Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Fri, 2 Dec 2022 17:11:44 -0600 Subject: [PATCH 1/3] fix: Fixed an issue where BatchedSendQueue was including the HeadIndex twice when copying data, which was causing stream corruption when the data exceeded a certain throughput. --- .../Runtime/Transports/UTP/BatchedSendQueue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs index c305884e16..6f81eea442 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/BatchedSendQueue.cs @@ -226,7 +226,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer) { writer.WriteInt(messageLength); - var messageOffset = HeadIndex + reader.GetBytesRead(); + var messageOffset = reader.GetBytesRead(); WriteBytes(ref writer, (byte*)m_Data.GetUnsafePtr() + messageOffset, messageLength); writerAvailable -= sizeof(int) + messageLength; From 5975927ae96b22158e89efae09d4bf380da45417 Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Mon, 5 Dec 2022 11:18:38 -0600 Subject: [PATCH 2/3] Added a test --- .../Tests/Editor/Transports/BatchedSendQueueTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Transports/BatchedSendQueueTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Transports/BatchedSendQueueTests.cs index eac6b73f6e..3438c60c1c 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Transports/BatchedSendQueueTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Transports/BatchedSendQueueTests.cs @@ -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] From 4f449a219b45ab35a23640ee8aad8ce437daa21d Mon Sep 17 00:00:00 2001 From: Kitty Draper Date: Mon, 5 Dec 2022 12:16:04 -0600 Subject: [PATCH 3/3] Changelog --- com.unity.netcode.gameobjects/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 3799484b5c..56de856723 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -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)