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 @@ -24,6 +24,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Issue where a growable `FastBufferWriter` created with a size of 0 never returned from its first write or `TryBeginWrite` call that needed the buffer to grow. (#4224)
- Issue where a `FastBufferReader` created with an offset and the default length of -1 read past the end of its source. The `ArraySegment<byte>` overload that takes an offset now applies it from the start of the segment. (#4222)
- Issue where a client promoted to session owner could throw an exception when synchronizing a newly joining client. (#4214)
- Issue where `NetworkManager.OnNetCodeDisconnect` was not invoked when a connection closed during a hybrid mode session, only when the session shut down. (#4209)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public unsafe BitWriter EnterBitwiseContext()

internal unsafe void Grow(int additionalSizeRequired)
{
var desiredSize = Handle->Capacity * 2;
var desiredSize = Math.Max(Handle->Capacity * 2, 1);
while (desiredSize < Position + additionalSizeRequired)
{
desiredSize *= 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,17 @@ public void WhenBufferGrowthRequiredIsMoreThanDouble_BufferGrowsEnoughToContainR
}
}

[Test]
public void WhenGrowingWriterStartsWithZeroSize_BufferGrows()
{
using var growingWriter = new FastBufferWriter(0, Allocator.Temp, 64);
Assert.IsTrue(growingWriter.TryBeginWrite(4));
Assert.AreEqual(4, growingWriter.Capacity);

growingWriter.WriteByteSafe(1);
Assert.AreEqual(new byte[] { 1 }, growingWriter.ToArray());
}

[Test]
public void WhenTryingToWritePastMaxCapacity_GrowthDoesNotOccurAndTryBeginWriteReturnsFalse()
{
Expand Down
Loading