Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Exception in OnStartClient : An element with the same key already exists in the dictionary. #48

Closed
GabeBigBoxVR opened this issue Aug 29, 2017 · 12 comments

Comments

@GabeBigBoxVR
Copy link

GabeBigBoxVR commented Aug 29, 2017

Context

I'm using the HLAPI setup in Unity 2017.1.0p4 and i'm getting exceptions when a client tries to join the game that is being self-hosted on another computer.

Screenshot of Log: http://imgur.com/a/MSoYU

[Dissonance:Network] HlapiClient: Object reference not set to an instance of an object

[Dissonance:Network] HlapiClient: Object reference not set to an instance of an object
0x000000014098BB0B (Unity) 
0x000000014098F03F (Unity) 
0x0000000140D37220 (Unity) 
0x000000014107C666 (Unity) 
0x000000014107CE3C (Unity) 
0x000000014186C012 (Unity) 
0x000000003B16558B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
0x000000003B165474 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) 
0x000000003B164D75 (Mono JIT Code) [Logger.cs:47] UnityEngine.Logger:Log (UnityEngine.LogType,object) 
0x000000003D7BEF73 (Mono JIT Code) [DebugBindings.gen.cs:124] UnityEngine.Debug:LogError (object) 
0x000000003D79B750 (Mono JIT Code) [Log.cs:106] Dissonance.Logs/LogMessage:Log () 
0x000000003D79B2FD (Mono JIT Code) [Log.cs:135] Dissonance.Logs:SendLogMessage (string,Dissonance.LogLevel) 
0x000000003D79B010 (Mono JIT Code) [Log.cs:207] Dissonance.Log:WriteLog (Dissonance.LogLevel,string) 
0x000000003D7BEE94 (Mono JIT Code) [Log.cs:368] Dissonance.Log:Error (string) 
0x000000003D7B59A9 (Mono JIT Code) [BaseClient.cs:166] Dissonance.Networking.BaseClient`3<Dissonance.Integrations.UNet_HLAPI.HlapiServer, Dissonance.Integrations.UNet_HLAPI.HlapiClient, Dissonance.Integrations.UNet_HLAPI.HlapiConn>:Update () 
0x000000003D7B55F8 (Mono JIT Code) [HlapiClient.cs:60] Dissonance.Integrations.UNet_HLAPI.HlapiClient:Update () 
0x000000003D7B5133 (Mono JIT Code) [BaseCommsNetwork.cs:143] Dissonance.Networking.BaseCommsNetwork`5/Session<Dissonance.Integrations.UNet_HLAPI.HlapiServer, Dissonance.Integrations.UNet_HLAPI.HlapiClient, Dissonance.Integrations.UNet_HLAPI.HlapiConn, Dissonance.Unit, Dissonance.Unit>:Update () 
0x000000003D799DC1 (Mono JIT Code) [BaseCommsNetwork.cs:296] Dissonance.Networking.BaseCommsNetwork`5<Dissonance.Integrations.UNet_HLAPI.HlapiServer, Dissonance.Integrations.UNet_HLAPI.HlapiClient, Dissonance.Integrations.UNet_HLAPI.HlapiConn, Dissonance.Unit, Dissonance.Unit>:Update () 
0x000000003D799126 (Mono JIT Code) [HlapiCommsNetwork.cs:56] Dissonance.Integrations.UNet_HLAPI.HlapiCommsNetwork:Update () 
0x0000000012976C52 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FFB70BB5B67 (mono) mono_set_defaults

Exception in OnStartClient:An element with the same key already exists in the dictionary.

Exception in OnStartClient:An element with the same key already exists in the dictionary.   at System.Collections.Generic.Dictionary`2[System.String,Dissonance.IDissonancePlayer].Add (System.String key, IDissonancePlayer value) [0x0007e] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404 
  at Dissonance.DissonanceComms.TrackPlayerPosition (IDissonancePlayer player) [0x0005b] in C:\src\c\Client\Assets\Plugins\Dissonance\DissonanceComms.cs:711 
  at Dissonance.Integrations.UNet_HLAPI.HlapiPlayer.StartTracking () [0x0003a] in C:\src\c\Client\Assets\Plugins\Dissonance\Resources\Integrations\UNet_HLAPI\HlapiPlayer.cs:149 
  at Dissonance.Integrations.UNet_HLAPI.HlapiPlayer.OnStartClient () [0x00018] in C:\src\c\Client\Assets\Plugins\Dissonance\Resources\Integrations\UNet_HLAPI\HlapiPlayer.cs:114 
  at UnityEngine.Networking.NetworkIdentity.OnStartClient () [0x0008d] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:374 
0x000000014098BB0B (Unity) 
0x000000014098F03F (Unity) 
0x0000000140D37220 (Unity) 
0x000000014107C666 (Unity) 
0x000000014107CE3C (Unity) 
0x000000014186C012 (Unity) 
0x000000003B16558B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
0x000000003B165474 (Mono JIT Code) [DebugLogHandler.cs:9] UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) 
0x000000003B164D75 (Mono JIT Code) [Logger.cs:47] UnityEngine.Logger:Log (UnityEngine.LogType,object) 
0x000000003D7BEF73 (Mono JIT Code) [DebugBindings.gen.cs:124] UnityEngine.Debug:LogError (object) 
0x0000000051BBBBB1 (Mono JIT Code) [NetworkIdentity.cs:378] UnityEngine.Networking.NetworkIdentity:OnStartClient () 
0x0000000051BB7596 (Mono JIT Code) [ClientScene.cs:505] UnityEngine.Networking.ClientScene:ApplySpawnPayload (UnityEngine.Networking.NetworkIdentity,UnityEngine.Vector3,byte[],UnityEngine.Networking.NetworkInstanceId,UnityEngine.GameObject) 
0x0000000051BB195D (Mono JIT Code) [ClientScene.cs:552] UnityEngine.Networking.ClientScene:OnObjectSpawn (UnityEngine.Networking.NetworkMessage) 
0x000000003D8115EA (Mono JIT Code) [NetworkConnection.cs:469] UnityEngine.Networking.NetworkConnection:HandleReader (UnityEngine.Networking.NetworkReader,int,int) 
0x000000003D810ABB (Mono JIT Code) [NetworkConnection.cs:425] UnityEngine.Networking.NetworkConnection:HandleBytes (byte[],int,int) 
0x000000003D81095F (Mono JIT Code) [NetworkConnection.cs:576] UnityEngine.Networking.NetworkConnection:TransportReceive (byte[],int,int) 
0x000000003D7CCB52 (Mono JIT Code) [NetworkClient.cs:753] UnityEngine.Networking.NetworkClient:Update () 
0x000000003D7CBD8D (Mono JIT Code) [NetworkClient.cs:965] UnityEngine.Networking.NetworkClient:UpdateClients () 
0x000000003D7C8794 (Mono JIT Code) [NetworkIdentity.cs:1091] UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate () 
0x0000000012930CFE (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)

Expected Behavior

Shouldn't see an exception when connecting

Actual Behavior

Exception

Steps to Reproduce

We're using the stock settings that were in the tutorial, channels 0 and 1 for comms.

  1. Setup a in-editor non-dedicate server running with HLAPI in 2017 and host the connection. Once connection has been completed, load into a new map and load the character prefab. We are using the VoiceBroadcastTrigger on the player object.
  2. Server starts up and runs properly and everything seems to work.
  3. Connect a client using to the server.

Verify: Error occurs

Your Environment

  • Dissonance version used: v3.0.0

  • Unity version: Unity 2017.1.0p4

  • Editor Operating System and version: Microsoft Windows 10

  • Build Settings: Windows, x86_64, In Editor

@martindevans
Copy link
Member

martindevans commented Aug 29, 2017

Hi Gabe,

Do you get this same error when running the HLAPI demo scene? That also uses triggers on the player prefab, so it sounds like it ought to suffer from the same problem.

The first error is coming from inside this try block in BaseClient:

try
{
  //Update components
  _serverNegotiator.Update();
  _sendQueue.Update();
  _voiceReceiver.Update();

  //Poll network layer for more packets
  ReadMessages();

  return ClientStatus.Ok;
}

Would you mind drilling into this and finding what the null reference is? If you're not sure how to do that just comment out the following lines and it'll give me a good hint:

//try
//return ClientStatus.Ok;
//catch (Exception e)
//Log.Error(e.Message);
//return ClientStatus.Error;
//finally

// at the end of the method, add in
return ClientStatus.Ok;

Make sure to add the lines back in afterwards!

The second error looks like something that has already been fixed in the dev branch. Once we've tracked down the first error I can send you a new package with that fix included :)

@GabeBigBoxVR
Copy link
Author

I'm not at the office yet, but I'll check the demo scene to see if it repro's in there.

I tracked down the null reference last night and it's coming from the HLAPIClient in ReadMessages(). In the first frame of a newly loaded scene, the connection property on NetworkHost.singleton.client.connection is null. (or something like that, I'm recalling from memory until I get into the office) After the the first frame, the property has a value.

@GabeBigBoxVR
Copy link
Author

GabeBigBoxVR commented Aug 29, 2017

HlapiClient.cs line 95. Connection is null for the first frame only.

  if (!NetworkManager.singleton.client.connection.SendBytes(_sendWriter.AsArray(), length, channel))     

@GabeBigBoxVR
Copy link
Author

We also just tested the HLAPI demo scene and it does work. I suspect there's something going on with our setup.

@martindevans
Copy link
Member

HlapiClient.cs line 95. Connection is null for the first frame only.

That's odd - that code doesn't run until NetworkClient.active is true which I would expect to indicate a non null connection! You could explicitly check for this case, in HlapiCommsNetwork:Update there's a check which starts the Dissonance client/server when the HLAPI client/server are ready.

if (IsInitialized)
{
    var networkActive = NetworkManager.singleton.isNetworkActive && (NetworkServer.active || NetworkClient.active);
    if (networkActive)
    {
        //setup stuff
    }
}

You could add another check in there to ensure that the connection is not null:

var networkActive = NetworkManager.singleton.isNetworkActive && (NetworkServer.active || NetworkClient.active) && (!NetworkClient.active || (NetworkManager.singleton.client != null && NetworkManager.singleton.client.connection != null));

This will delay Dissonance startup until the connection is not null (but only if the client is active). If that works for you I'll include it in the next Dissonance version.

I suspect there's something going on with our setup.

It's intended to be very forgiving of slightly wrong setups - for example the check I referenced above means it doesn't care if it's active before a network session even exists - it just waits until HLAPI is ready. Even if you have set up something very wrong I'd still like for Dissonance to detect that and print a more useful message than a null reference exception!

@GabeBigBoxVR
Copy link
Author

Hey Martin,

I sorted it out, it looks like my setup had multiple room triggers in the scene. After removing those it appears to be working properly, but we still get those exceptions but at least audio is now playing.

@GabeBigBoxVR
Copy link
Author

I'm going to add a null check on the connection and to have it return true if the connection is null as per a setup. Then after that it should be good.

@martindevans
Copy link
Member

it looks like my setup had multiple room triggers in the scene

Multiple room triggers is totally fine! You can have as many room triggers as you like - that's totally expected (e.g. one global, one per team, one proximity per player).

I'm going to add a null check on the connection

Do you mean the var networkActive = ... check I suggested above? If not, did you try that and did it work?

@GabeBigBoxVR
Copy link
Author

GabeBigBoxVR commented Sep 5, 2017 via email

@martindevans
Copy link
Member

I've already got a change merged into the dev branch so I can send you a build right now if you'd like - just send me your order number.

Out of interest what change did you make to fix this yourself?

@GabeBigBoxVR
Copy link
Author

GabeBigBoxVR commented Sep 5, 2017 via email

@martindevans
Copy link
Member

Dissonance 3.0.1 has just released on the Unity asset store, this includes the changes made to resolve this issue so I'll close it now. If the problem persists please feel free to continue posting in this thread. If you're happy with how this issue was handled please consider rating and reviewing us on the asset store!

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

No branches or pull requests

2 participants