From 0983b17acbe470e278e8029f327e63e6f2f3a2e3 Mon Sep 17 00:00:00 2001 From: scamiv <6170744+scamiv@users.noreply.github.com> Date: Wed, 26 Nov 2025 15:22:34 +0100 Subject: [PATCH] fix sab detection --- src/core/game/TerrainMapLoader.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/game/TerrainMapLoader.ts b/src/core/game/TerrainMapLoader.ts index 9b39f1137..2f6757630 100644 --- a/src/core/game/TerrainMapLoader.ts +++ b/src/core/game/TerrainMapLoader.ts @@ -39,7 +39,16 @@ export async function loadTerrainMap( sharedStateBuffer?: SharedArrayBuffer, ): Promise { const useCache = sharedStateBuffer === undefined; - if (useCache) { + const canUseSharedBuffers = + typeof SharedArrayBuffer !== "undefined" && + typeof Atomics !== "undefined" && + typeof (globalThis as any).crossOriginIsolated === "boolean" && + (globalThis as any).crossOriginIsolated === true; + + // Don't use cache if we can create SharedArrayBuffer but none was provided + const shouldUseCache = useCache && !canUseSharedBuffers; + + if (shouldUseCache) { const cached = loadedMaps.get(map); if (cached !== undefined) return cached; } @@ -96,9 +105,8 @@ export async function loadTerrainMap( ? stateBuffer : undefined, }; - if (useCache) { - loadedMaps.set(map, result); - } + // Always cache the result, but only use cache when appropriate + loadedMaps.set(map, result); return result; }