Skip to content

Commit 350440a

Browse files
authored
fix: scene message handler duplicate key (#8821)
1 parent 646ca0d commit 350440a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Explorer/Assets/DCL/Infrastructure/CrdtEcsBridge/JsModulesImplementation/Communications/SceneCommunicationPipe.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,22 @@ public void AddSceneMessageHandler(string sceneId, ISceneCommunicationPipe.MsgTy
8888
SubscriberKey key = new (sceneId, msgType);
8989

9090
lock (sceneMessageHandlers)
91-
sceneMessageHandlers.Add(key, onSceneMessage);
91+
{
92+
// See: https://github.com/decentraland/unity-explorer/issues/8183
93+
sceneMessageHandlers[key] = onSceneMessage;
94+
}
9295
}
9396

9497
public void RemoveSceneMessageHandler(string sceneId, ISceneCommunicationPipe.MsgType msgType, ISceneCommunicationPipe.SceneMessageHandler onSceneMessage)
9598
{
9699
SubscriberKey key = new (sceneId, msgType);
97100

98101
lock (sceneMessageHandlers)
99-
sceneMessageHandlers.Remove(key);
102+
{
103+
// Since message handlers might be replaced, we need to check that the removal of the key belongs to the handler
104+
if (sceneMessageHandlers.TryGetValue(key, out var current) && current == onSceneMessage)
105+
sceneMessageHandlers.Remove(key);
106+
}
100107
}
101108

102109
public void SendMessage(ReadOnlySpan<byte> message, string sceneId, ISceneCommunicationPipe.ConnectivityAssertiveness assertiveness, CancellationToken ct, string? specialRecipient = null)

0 commit comments

Comments
 (0)