From ab952812d68cdb97bfbc4a0a06b628a31b792389 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:51:10 +0900 Subject: [PATCH] chore: update internal code --- .../Runtime/Internal/Utilities/FrameCache.cs | 41 ++++++++++++++----- .../src/Runtime/Internal/Utilities/Misc.cs | 1 + 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Packages/src/Runtime/Internal/Utilities/FrameCache.cs b/Packages/src/Runtime/Internal/Utilities/FrameCache.cs index 4eead7c..2c727f8 100644 --- a/Packages/src/Runtime/Internal/Utilities/FrameCache.cs +++ b/Packages/src/Runtime/Internal/Utilities/FrameCache.cs @@ -19,7 +19,11 @@ namespace Coffee.UIEffectInternal #endif private static void Clear() { - s_Caches.Clear(); + lock (s_Caches) + { + s_Caches.Clear(); + } + UIExtraCallbacks.onLateAfterCanvasRebuild -= ClearAllCache; UIExtraCallbacks.onLateAfterCanvasRebuild += ClearAllCache; } @@ -74,21 +78,27 @@ namespace Coffee.UIEffectInternal private static void ClearAllCache() { - foreach (var cache in s_Caches.Values) + lock (s_Caches) { - cache.Clear(); + foreach (var cache in s_Caches.Values) + { + cache.Clear(); + } } } private static FrameCacheContainer GetFrameCache() { - var t = typeof(T); - if (s_Caches.TryGetValue(t, out var frameCache)) return frameCache as FrameCacheContainer; + lock (s_Caches) + { + var t = typeof(T); + if (s_Caches.TryGetValue(t, out var frameCache)) return frameCache as FrameCacheContainer; - frameCache = new FrameCacheContainer(); - s_Caches.Add(t, frameCache); + frameCache = new FrameCacheContainer(); + s_Caches.Add(t, frameCache); - return (FrameCacheContainer)frameCache; + return (FrameCacheContainer)frameCache; + } } private interface IFrameCache @@ -102,17 +112,26 @@ namespace Coffee.UIEffectInternal public void Clear() { - _caches.Clear(); + lock (_caches) + { + _caches.Clear(); + } } public bool TryGet((int, int) key, out T result) { - return _caches.TryGetValue(key, out result); + lock (_caches) + { + return _caches.TryGetValue(key, out result); + } } public void Set((int, int) key, T result) { - _caches[key] = result; + lock (_caches) + { + _caches[key] = result; + } } } } diff --git a/Packages/src/Runtime/Internal/Utilities/Misc.cs b/Packages/src/Runtime/Internal/Utilities/Misc.cs index b281a9c..4232450 100644 --- a/Packages/src/Runtime/Internal/Utilities/Misc.cs +++ b/Packages/src/Runtime/Internal/Utilities/Misc.cs @@ -13,6 +13,7 @@ using UnityEditor.SceneManagement; #else using UnityEditor.Experimental.SceneManagement; #endif + #endif namespace Coffee.UIEffectInternal