Skip to content

ArgumentNullException ByteBuffer#1021

Open
f2069 wants to merge 1 commit intoFirstGearGames:mainfrom
f2069:fix-iterate-outgoing
Open

ArgumentNullException ByteBuffer#1021
f2069 wants to merge 1 commit intoFirstGearGames:mainfrom
f2069:fix-iterate-outgoing

Conversation

@f2069
Copy link
Contributor

@f2069 f2069 commented Mar 7, 2026

Periodically, when one of the client disconnects from the clienthost in the build, this error occurs.

ArgumentNullException: Value cannot be null.
Parameter name: array
System.ArraySegment`1[T]..ctor (T[] array, System.Int32 offset, System.Int32 count) (at <00000000000000000000000000000000>:0)
FishNet.Managing.Transporting.TransportManager.<IterateOutgoing>g__ProcessPacketBundle|69_2 (FishNet.Connection.PacketBundle ppb, System.Boolean isLast, FishNet.Managing.Transporting.TransportManager+<>c__DisplayClass69_0& , FishNet.Managing.Transporting.TransportManager+<>c__DisplayClass69_1& , FishNet.Managing.Transporting.TransportManager+<>c__DisplayClass69_2& ) (at <00000000000000000000000000000000>:0)
FishNet.Managing.Transporting.TransportManager.<IterateOutgoing>g__SendAsServer|69_0 (FishNet.Managing.Transporting.TransportManager+<>c__DisplayClass69_0& ) (at <00000000000000000000000000000000>:0)
FishNet.Managing.Transporting.TransportManager.IterateOutgoing (System.Boolean asServer) (at <00000000000000000000000000000000>:0)
FishNet.Managing.Timing.TimeManager.IncreaseTick () (at <00000000000000000000000000000000>:0)
FishNet.Managing.Timing.TimeManager.TickUpdate () (at <00000000000000000000000000000000>:0)

// Length should always be more than 0 but check to be safe.
if (ppb.GetBuffer(i, out ByteBuffer bb))
{
ArraySegment<byte> segment = new(bb.Data, 0, bb.Length);

ArraySegment<byte> segment = new(bb.Data, 0, bb.Length); // - bb.Data is null

Apparently, when disconnecting, NetworkConnection.ResetState and ByteBuffer.Dispose are called, which sets the Data field to null. However, the HasData flag remains true.

public void Dispose()
{
if (Data != null)
ByteArrayPool.Store(Data);
Data = null;
}

Because of this, the PacketBundle.GetBuffer method returns a buffer that has already been reset to zero, but the further logic breaks down.

bb = _buffers[index];
return bb.HasData;
}

I'm not 100% sure that this fix won't break some other logic, but it's definitely worth paying attention to the incorrect reset of the ByteBuffer state when calling ByteBuffer.Dispose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant