From c76584ee2114058c38cd00f8545c9f0548cbdd65 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 11 Oct 2026 13:06:04 +0200 Subject: [PATCH] Entity.VisibilitySources: a ReadOnlyDictionary created once over the private field, so a cast back to Dictionary fails Finding one-writer-castable. Test commit follows; builds. Co-Authored-By: Claude Opus 5.5 --- Assets/Scripts/ServerShared/Entity.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index bf30ee927..bbca6a2ad 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -5,6 +5,7 @@ using GameCult.Caching; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using MessagePack; using UniRx; @@ -87,7 +88,9 @@ public abstract class Entity public readonly Dictionary Messages = new Dictionary(); private readonly Dictionary _visibilitySources = new Dictionary(); // A read-only view: the only writes are SetSignature and the decay loop in Update, both below. - public IReadOnlyDictionary VisibilitySources => _visibilitySources; + // A ReadOnlyDictionary over the private field, created once: a cast back to Dictionary fails. + private ReadOnlyDictionary _visibilityView; + public IReadOnlyDictionary VisibilitySources => _visibilityView ??= new ReadOnlyDictionary(_visibilitySources); // The one writer of VisibilitySources (the decay loop in Update is the one decayer). Every light signature // names its channel and the item that produced it (null for the hull).