com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

Netcode 1.5.1 crash in Build using Relay

Open Schuebl opened this issue 2 years ago • 1 comments

Description

I'm actually try to initialize a Relay service with this simple code based on the Codemonkey Relay-Service tutorial. Authorization has been completed successfully:

private async void CreateRelayConnection()
{
      try
      {
             Allocation allocation = await RelayService.Instance.CreateAllocationAsync(4);
             var JoinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
             Debug.Log("JoinCode: " + JoinCode);
 
             var transport = NetworkManager.Singleton.GetComponent<UnityTransport>();
             if(null!= transport)
             {
                   transport.SetHostRelayData(
                        allocation.RelayServer.IpV4,
                        (ushort)allocation.RelayServer.Port,
                        allocation.AllocationIdBytes,
                        allocation.Key,
                        allocation.ConnectionData
                   );
                   Debug.Log("Relay Server initialized");
                   NetworkManager.Singleton.StartHost();
                   Debug.Log("Host successfull started");
             }
     }
     catch(RelayServiceException e)
     {
           Debug.Log(e.ToString());
     }
 }

Starting everything from Unity, this code works like a charm and the service is initialized successfully. If I use a (Development) Build this code fails when calling StartHost() with this failure:

UnloadTime: 0.905900 ms Data created: Main Menu Signed in Anonymously: fuiSi2okDQL0SDCXWWF8QB8D86Q9 best region is europe-west2 JoinCode generated: K6DNCD Relay Server initialized ArgumentException: An item with the same key has already been added. Key: -1 at System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000dd] in <605bf8b31fcb444b85176da963870aa7>:0 at System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <605bf8b31fcb444b85176da963870aa7>:0 at Unity.Netcode.NetworkSceneManager.GenerateScenesInBuild () [0x0004a] in :0 at Unity.Netcode.NetworkSceneManager..ctor (Unity.Netcode.NetworkManager networkManager) [0x00091] in :0 at Unity.Netcode.NetworkManager.Initialize (System.Boolean server) [0x0013f] in :0 at Unity.Netcode.NetworkManager.StartHost () [0x00030] in :0 at binrev.netcode.UIHostConnection.OpenConnection () [0x00066] in <9624421bb2774c9980efe3ed0782b5b9>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <605bf8b31fcb444b85176da963870aa7>:0 at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <420f675e2d6b4f17877563ada0d329b3>:0 at UnityEngine.UnitySynchronizationContext.Exec () [0x0005d] in <420f675e2d6b4f17877563ada0d329b3>:0 at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00014] in <420f675e2d6b4f17877563ada0d329b3>:0

NullReferenceException: Object reference not set to an instance of an object at Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) [0x0004c] in :0 at Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) [0x00021] in :0 at Unity.Netcode.NetworkUpdateLoop+NetworkPostLateUpdate+<>c.<CreateLoopSystem>b__0_0 () [0x00000] in :0

The NullReferenceException then is thrown endless every second. The Code is triggert by a simple UIScript UIHostConnection, listen to a Button which invokes the OpenConnection method. This method only triggers this code. The UI script is inherited from MonoBehaviour. I also tried to use NetworkBehaviour, but this has no different effect.

Reproduce Steps

  1. Run this snipped in Unity, anything works like expected.
  2. Create a Build (Development), this snipped crashes on StartHost call

Environment

  • OS: Windows 10
  • Unity Version: 2022.3.3f1
  • Netcode Version: 1.5.1
  • Relay Version: 1.0.5

Additional Context

Player.log HostConnection.txt

Schuebl avatar Jun 27 '23 11:06 Schuebl

@Schuebl Do you have any special scenes added to your scenes in build list and/or are you programmatically generating a scene?

NoelStephensUnity avatar Nov 06 '23 17:11 NoelStephensUnity