Skip to content

Commit 3f70876

Browse files
committed
Improved BitWriter & BitReader warnings
1 parent fd059e3 commit 3f70876

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitReader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Runtime.InteropServices;
55
using System.Text;
6+
using UnityEngine;
67

78
namespace MLAPI.NetworkingManagerComponents.Binary
89
{
@@ -17,6 +18,7 @@ public class BitReader : IDisposable
1718
private byte[] readFrom;
1819
private long bitCount = 0;
1920

21+
private static int pools = 0;
2022
private static readonly Queue<BitReader> readerPool = new Queue<BitReader>();
2123

2224
private BitReader(byte[] readFrom)
@@ -28,7 +30,10 @@ public static BitReader Get(byte[] readFrom)
2830
{
2931
if (readerPool.Count == 0)
3032
{
33+
if (pools > 10)
34+
Debug.LogWarning("MLAPI: There are more than 10 BitReaders. Have you forgotten do dispose? (More readers hurt performance)");
3135
BitReader reader = new BitReader(readFrom);
36+
pools++;
3237
return reader;
3338
}
3439
else

MLAPI/NetworkingManagerComponents/Binary/BitWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static BitWriter Get()
8686
{
8787
if (writerPool.Count == 0)
8888
{
89-
Debug.LogWarning("MLAPI: There can be no more than 10 BitWriters. Have you forgotten do dispose? (It will still work with worse performance)");
89+
Debug.LogWarning("MLAPI: There are more than 10 BitWriters. Have you forgotten do dispose? (It will still work with worse performance)");
9090
return new BitWriter() { outsidePool = true };
9191
}
9292
else

0 commit comments

Comments
 (0)