Skip to content

Commit

Permalink
fix: fixing resize buffer so that it uses byte capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Aug 1, 2021
1 parent d48091e commit 927fe95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Assets/Mirage/Runtime/Serialization/NetworkWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,20 @@ public NetworkWriter(int minByteCapacity, bool allowResize)
}


void ResizeBuffer(int minCapacity)
void ResizeBuffer(int minBitCapacity)
{
int minByteCapacity = minBitCapacity / 8;
int size = managedBuffer.Length;
while (size < minCapacity)
while (size < minByteCapacity)
{
size *= 2;
if (size > MaxBufferSize)
{
throw new InvalidOperationException($"Can not resize buffer to {size} because it is above max value of {MaxBufferSize}");
throw new InvalidOperationException($"Can not resize buffer to {size} bytes because it is above max value of {MaxBufferSize}");
}
}

Debug.LogWarning($"Resizing buffer, new size:{size}");
Debug.LogWarning($"Resizing buffer, new size:{size} bytes");

FreeHandle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BitPackingResizeTest
private NetworkReader reader;

[SetUp]
public void OneTimeSetUp()
public void SetUp()
{
writer = new NetworkWriter(1300, true);
reader = new NetworkReader();
Expand All @@ -18,8 +18,11 @@ public void OneTimeSetUp()
[TearDown]
public void TearDown()
{
// we have to clear these each time so that capactity doesn't effect other tests
writer.Reset();
writer = null;
reader.Dispose();
reader = null;
}

[Test]
Expand Down

0 comments on commit 927fe95

Please sign in to comment.