Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
739 stars 185 forks source link

fix: Fix KeyNotFoundException in RTCPeerConnection #865

Closed karasusan closed 1 year ago

karasusan commented 1 year ago

RTCPeerConnection throws KeyNotFoundException below when firing the callback after disposing the its instance.

KeyNotFoundException: The given key was not present in the dictionary. at 
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x00000] in 
<00000000000000000000000000000000>:0 at Unity.WebRTC.RTCPeerConnection.FindObserver[T] (System.IntPtr ptr) [0x00000] 
in <00000000000000000000000000000000>:0 at Unity.WebRTC.WebRTC+<>c__DisplayClass32_0.
<OnSetRemoteDescription>b__0 () [0x00000] in <00000000000000000000000000000000>:0 at 
Unity.WebRTC.WebRTC.SendOrPostCallback (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 at 
Unity.WebRTC.ExecutableUnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in 
<00000000000000000000000000000000>:0 at Unity.WebRTC.ExecutableUnitySynchronizationContext.Execute () [0x00000] in 
<00000000000000000000000000000000>:0 at 
Unity.WebRTC.ExecutableUnitySynchronizationContext.ExecuteAndAppendNextExecute () [0x00000] in 
<00000000000000000000000000000000>:0 at Unity.WebRTC.ExecutableUnitySynchronizationContext.SendOrPostCallback 
(System.Object state) [0x00000] in <00000000000000000000000000000000>:0 at 
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 at 
UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 at 
UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00000] in <00000000000000000000000000000000>:0

Fixed the issue using TryGetValue.