colyseus / colyseus-unity-sdk

⚔ Colyseus Multiplayer SDK for Unity
https://docs.colyseus.io/getting-started/unity-sdk/
MIT License
371 stars 100 forks source link

ColyseusRoom.OnMessage<> throws exception if the sessionId exists #221

Open Alaadel opened 7 months ago

Alaadel commented 7 months ago

I clicked Join twice, and got an exception:

ArgumentException: An item with the same key has already been added. Key: msgStart
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <b89873cb176e44a995a4781c7487d410>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <b89873cb176e44a995a4781c7487d410>:0)
Colyseus.ColyseusRoom`1[T].OnMessage[MessageType] (System.String type, System.Action`1[T] handler) (at ./Library/PackageCache/io.colyseus.sdk@77fca87056/Runtime/Colyseus/Room/ColyseusRoom.cs:358)

System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <b89873cb176e44a995a4781c7487d410>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <10871f9e312b442cb78b9b97db88fdcb>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <10871f9e312b442cb78b9b97db88fdcb>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <10871f9e312b442cb78b9b97db88fdcb>:0)

I think it should check first, and log any errors instead of throwing exceptions.