Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Error: ArgumentOutOfRangeException: ArgumentOutOfRange_NeedNonNegNum Parameter name: count

Discussion in 'Relay' started by davidpetersims, Apr 27, 2023.

  1. davidpetersims

    davidpetersims

    Joined:
    Oct 16, 2018
    Posts:
    5
    I've been experiencing a crash when a client connects to a host. It's on the host end, and it appears to be happening when the client is connecting.

    It's only started happening this week, and even though I've rolled back my code and scenes to last week's version, I'm still getting the crash. The code I'm using had been working on iOS, Android and Windows devices successfully for months.

    I'm using relay with lobby. The lobby is created successfully on the host, and the client successfully receives the lobby code and relay connection data. However, once the client attempts to connect, I get this error on the host:

    ArgumentOutOfRangeException: ArgumentOutOfRange_NeedNonNegNum
    Parameter name: count
    System.ArraySegment`1[T]..ctor (System.Byte[] array, System.Int32 offset, System.Int32 count) (at <697c5b3fd45741b99b7cab46a4b7b6ac>:0)
    Unity.Netcode.Transports.UTP.BatchedReceiveQueue.PopMessage () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Transports/UTP/BatchedReceiveQueue.cs:100)
    Unity.Netcode.Transports.UTP.UnityTransport.ReceiveMessages (System.UInt64 clientId, Unity.Networking.Transport.NetworkPipeline pipeline, Unity.Networking.Transport.DataStreamReader dataReader) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Transports/UTP/UnityTransport.cs:787)
    Unity.Netcode.Transports.UTP.UnityTransport.ProcessEvent () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Transports/UTP/UnityTransport.cs:844)
    Unity.Netcode.Transports.UTP.UnityTransport.Update () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.2.0/Runtime/Transports/UTP/UnityTransport.cs:877)

    Here's the code I'm using to connect:

    Code (CSharp):
    1.     async Task<Lobby> QuickJoinLobby()
    2.     {
    3.         if (loading)
    4.             return null;
    5.         try
    6.         {
    7.             loading = true;
    8.             multiPlayer.AddLog("Searching for Game...");
    9.             var lLobby = await Lobbies.Instance.QuickJoinLobbyAsync();
    10.             if (ApplicationData.Debug)
    11.                 multiPlayer.AddLog("Found " + lLobby.Name + " Key:'" + lLobby.Data[JoinCodeKey].Value + "'");
    12.             var a = await RelayService.Instance.JoinAllocationAsync(lLobby.Data[JoinCodeKey].Value);
    13.             if (ApplicationData.Debug)
    14.             {
    15.                 try
    16.                 {
    17.                     multiPlayer.AddLog("IpV4:" + a.RelayServer.IpV4);
    18.                     multiPlayer.AddLog("Port:" + a.RelayServer.Port);
    19.                 }
    20.                 catch
    21.                 {
    22.                     multiPlayer.AddLog("Can't show connection data");
    23.                 }
    24.             }
    25.             transport.SetClientRelayData(a.RelayServer.IpV4, (ushort)a.RelayServer.Port, a.AllocationIdBytes, a.Key, a.ConnectionData, a.HostConnectionData);
    26.             multiPlayer.AddLog("Joining " + lLobby.Name);
    27.             hosting = false;
    28.             NetworkManager.Singleton.StartClient();
    29.             Debug.Log("Started Client");
    30.             loading = false;
    31.             return lLobby;
    32.         }
    33.         catch (LobbyServiceException e)
    34.         {
    35.             Debug.Log($"No lobbies available {e}");
    36.             loading = false;
    37.             return null;
    38.         }
    39.     }
    On the client, it happily shows to the "Started Client" in the log, but never gets to my OnClientConnectedCallback on either the host or the client.
    On the host, I get a debug message from netcode saying: [Netcode] Client Connected


    Here's the Network Manager setup:
    upload_2023-4-27_10-9-42.png
    And Unity Transport, during runtime:
    upload_2023-4-27_10-11-42.png
    And the Package Manager:
    upload_2023-4-27_10-13-0.png

    Also, Relay does appear to be up and running...
    upload_2023-4-27_10-23-42.png

    Any help would be appreciated! I'm starting to tear my hair out over this one!
     
  2. unity-justin

    unity-justin

    Unity Technologies

    Joined:
    Oct 27, 2021
    Posts:
    9
    Hi @davidpetersims, it's possible that this could be due to a bug that we've found in the "com.unity.transport" package. Could you try updating that package to the latest stable version (1.3.4), and let us know if that resolves your issue?
     
  3. davidpetersims

    davidpetersims

    Joined:
    Oct 16, 2018
    Posts:
    5
    Thank you @unity-justin! That has resolved the issue. However, I've had to downgrade back to the older version...

    It worked for the Android and Windows builds, but I can't get an iOS cloud build going unless I use an older version of unity. I can't seem to get any builds going for iOS using any unity 2022.2.x. I have an issue which I'll post on the cloud build thread about that.

    I also found what caused the issue in the first place. I was using unity 2022.2.5f1 for my dev environment. As of the start of the week, my cloud build switched to 2022.2.16f1 (as my settings are to use the latest 2022.2.x build) The issue seems to occur with this newer build using the older 1.3.1 version of com.unity.transport.

    Since my iOS cloud build can't use the newer version of unity, I've now downgraded transport back to 1.3.1, and got my iOS and Windows builds to detect the current unity version (which I also downgraded back to 2022.2.5.f1)
    So, now all my builds work, and connect seamlessly to each other as they previously did.

    Once I get my iOS cloud build working again with 2022.2.x builds, I'll upgrade transport to the latest.
     
  4. unity-justin

    unity-justin

    Unity Technologies

    Joined:
    Oct 27, 2021
    Posts:
    9
    I'm glad to hear that has resolved your runtime issue, and thanks for providing additional details and context. I'm sorry to hear that the latest version of cloud build is not working for iOS, and hope that is also resolved quickly.