Skip to content

Client NullReferenceException in OnReplicateRpc when NetworkTrafficStatistics is enabled #994

@e-scheer

Description

@e-scheer

This issue is related to the previously reported problem in
#948.

When NetworkTrafficStatistics is enabled, clients can receive replicate messages where sendingClient is null.
In NetworkBehaviour.Prediction.OnReplicateRpc, this results in a client-side NullReferenceException when accessing sendingClient.IsValid.


Environment

  • Unity: 6.x
  • FishNet: 4.6.12+
  • Client prediction enabled
  • NetworkTrafficStatistics enabled

Steps to Reproduce

  1. Enable NetworkTrafficStatistics in any FishNet demo scene
  2. Enable client prediction
  3. Start a server
  4. Start a client (ParrelSync / second editor)
  5. Trigger predicted movement or replication
  6. Observe client-side NullReferenceException

Observed Error

sendingClient is null in OnReplicateRpc, causing a NullReferenceException.


Expected Behavior

Network traffic statistics should not throw client-side exceptions.


Proposed Fix

Guard against a null sendingClient before accessing IsValid:

#if !UNITY_SERVER
if (_networkTrafficStatistics != null)
{
    bool fromServer = sendingClient != null && sendingClient.IsValid;
    _networkTrafficStatistics.AddInboundPacketIdData(
        PacketId.Replicate,
        GetRpcName(PacketId.Replicate, hash.Value),
        reader.Position - readerPositionAfterDebug + Managing.Transporting.TransportManager.PACKETID_LENGTH,
        gameObject,
        asServer: fromServer
    );
}
#endif

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolved Pending ReleaseIssue is resolved and will be available on the noted version.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions