A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(cocos): the layer drops what it kept of a session when the asset loader gives everything back
yhhd5daa3544ba7
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex fb74fcdb2..d08d89c1a 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -990,6 +990,7 @@ ResourceDef<AssetsClass>@internal dependentsOfAsset: (asset: AssetIdentity) => AssetIdentity[]@internal dependentsOfSource: (ref: string) => AssetIdentity[]@internal entityScopes: EntityAssetScopes+@internal epoch: number@internal handleBoundTypes: () => string[]@internal preparePrefab: (ref: string, overrides?: readonly PrefabOverride[]) => Promise<PreparedPrefab>@internal publishedRegistryAssets: <T>(type: string) => T[]diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 7ca9ac5a0..896edaced 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -990,6 +990,7 @@ ResourceDef<AssetsClass>@internal dependentsOfAsset: (asset: AssetIdentity) => AssetIdentity[]@internal dependentsOfSource: (ref: string) => AssetIdentity[]@internal entityScopes: EntityAssetScopes+@internal epoch: number@internal handleBoundTypes: () => string[]@internal preparePrefab: (ref: string, overrides?: readonly PrefabOverride[]) => Promise<PreparedPrefab>@internal publishedRegistryAssets: <T>(type: string) => T[]diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 1708bf081..b328269df 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -985,6 +985,7 @@ ResourceDef<AssetsClass>@internal dependentsOfAsset: (asset: AssetIdentity) => AssetIdentity[]@internal dependentsOfSource: (ref: string) => AssetIdentity[]@internal entityScopes: EntityAssetScopes+@internal epoch: number@internal handleBoundTypes: () => string[]@internal preparePrefab: (ref: string, overrides?: readonly PrefabOverride[]) => Promise<PreparedPrefab>@internal publishedRegistryAssets: <T>(type: string) => T[]diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex a422f8d7b..3ea31e524 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -985,6 +985,7 @@ ResourceDef<AssetsClass>@internal dependentsOfAsset: (asset: AssetIdentity) => AssetIdentity[]@internal dependentsOfSource: (ref: string) => AssetIdentity[]@internal entityScopes: EntityAssetScopes+@internal epoch: number@internal handleBoundTypes: () => string[]@internal preparePrefab: (ref: string, overrides?: readonly PrefabOverride[]) => Promise<PreparedPrefab>@internal publishedRegistryAssets: <T>(type: string) => T[]diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex cb7d67161..576033af0 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -985,6 +985,7 @@ ResourceDef<AssetsClass>@internal dependentsOfAsset: (asset: AssetIdentity) => AssetIdentity[]@internal dependentsOfSource: (ref: string) => AssetIdentity[]@internal entityScopes: EntityAssetScopes+@internal epoch: number@internal handleBoundTypes: () => string[]@internal preparePrefab: (ref: string, overrides?: readonly PrefabOverride[]) => Promise<PreparedPrefab>@internal publishedRegistryAssets: <T>(type: string) => T[]diff --git a/sdk/src/asset/Assets.ts b/sdk/src/asset/Assets.tsindex 8b33bd06b..5d16c9ec4 100644--- a/sdk/src/asset/Assets.ts+++ b/sdk/src/asset/Assets.ts@@ -446,6 +446,9 @@ export class Assets {private releasing_ = false;private preparations_ = new Set<DependencyRecorder>();+ /** @internal How many times everything this loader held has been given back: what a holder kept of an earlier one names things that are gone. */+ get epoch(): number { return this.resetEpoch_; }+private assertLoading_(epoch = this.resetEpoch_): void {if (this.releasing_ || epoch !== this.resetEpoch_) {throw new Error('Assets were released while loading; this request has no owner. Load it again.');diff --git a/sdk/src/cocos/prefabs.ts b/sdk/src/cocos/prefabs.tsindex 739911fe5..af2e3d876 100644--- a/sdk/src/cocos/prefabs.ts+++ b/sdk/src/cocos/prefabs.ts@@ -29,6 +29,7 @@ import { Prefab, preparedPrefabs } from './assets';const assetsOf = new WeakMap<World, AssetsClass>();let currentAssets: AssetsClass | null = null;+let currentEpoch = -1;const sessionListeners: Array<() => void> = [];/**@@ -77,13 +78,15 @@ export function declarePrefabSystem(): void {[Res(Assets), GetWorld()],(assets, world) => {if (!assets) return;- if (currentAssets && currentAssets !== assets) {+ const epoch = (assets as AssetsClass).epoch;+ if (currentAssets && (currentAssets !== assets || currentEpoch !== epoch)) {preparedPrefabs.clear();wanted.clear();inFlight.clear();for (const fn of sessionListeners) fn();}currentAssets = assets as AssetsClass;+ currentEpoch = epoch;assetsOf.set(world, assets as AssetsClass);if (wanted.size > 0) drain(assets as AssetsClass);},