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(assets): a remote group with no CDN root loads from the package
esengine844af0fc2ea3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6f4b1f4ed..b0cad0b46 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,15 @@ published separately; it ships inside the editor.### Fixed+- **A remote group with no CDN root loads from the package.** Its bytes ship inside+ the build (editor Play, a mini-game with no CDN), but the load path fell through to+ the asset's IDENTITY, which for a remote group is its authored address — a name the+ package does not carry. A hot-update demo exported to WeChat could not draw its own+ remote texture: `Failed to load image: assets/cdn/art.png`, while the file beside it+ was `remote/cdn/assets/cdn/art.ktx2.bin`. Where the bytes are is the realm's+ question, so its resolver answers it.++- **A mini-game reads an unset storage key as absent.** `wx.getStorageSync` answers akey that was never written with `''`, and the adapter passed that up as a storedvalue — so `Storage.getJSON` handed it to `JSON.parse`, which throws on it. A gamediff --git a/sdk/src/asset/Assets.ts b/sdk/src/asset/Assets.tsindex e566a3864..64bde709b 100644--- a/sdk/src/asset/Assets.ts+++ b/sdk/src/asset/Assets.ts@@ -2159,7 +2159,24 @@ export class Assets {// short of it.const remote = this.remoteAssetPath_(ref);if (remote != null) return remote;- return this.assetIdentity_(ref);+ // Deliberately NOT assetIdentity_: for a remote-group asset that answers+ // with the ADDRESS, and the package carries the STAGED name. Where the+ // bytes are is the realm's question, so its resolver gets it.+ const resolved = this.assetRefResolver_?.(ref) ?? ref;+ return this.catalog.resolve(resolved);+ }++ /** CDN url of `ref` when it names a `remote`-group asset AND a remote root is+ * set; null otherwise (caller falls back to the normal resolver). */+ private remoteAssetPath_(ref: string): string | null {+ if (!this.remoteRoot_) return null;+ const model = this.manifestModel_;+ if (!model) return null;+ const key = ref.startsWith(UUID_REF_PREFIX)+ ? ref.slice(UUID_REF_PREFIX.length).toLowerCase()+ : ref;+ const path = model.remoteAssetPath(key) ?? model.remoteAssetPath(ref);+ return path != null ? this.remoteUrlFor_(path) : null;}/**@@ -2180,19 +2197,6 @@ export class Assets {return this.catalog.resolve(resolved);}- /** CDN url of `ref` when it names a `remote`-group asset AND a remote root is- * set; null otherwise (caller falls back to the normal resolver). */- private remoteAssetPath_(ref: string): string | null {- if (!this.remoteRoot_) return null;- const model = this.manifestModel_;- if (!model) return null;- const key = ref.startsWith(UUID_REF_PREFIX)- ? ref.slice(UUID_REF_PREFIX.length).toLowerCase()- : ref;- const path = model.remoteAssetPath(key) ?? model.remoteAssetPath(ref);- return path != null ? this.remoteUrlFor_(path) : null;- }-// =========================================================================// Private// =========================================================================diff --git a/sdk/tests/hot-update-runtime.test.ts b/sdk/tests/hot-update-runtime.test.tsindex ce57d7140..f606b565d 100644--- a/sdk/tests/hot-update-runtime.test.ts+++ b/sdk/tests/hot-update-runtime.test.ts@@ -107,6 +107,59 @@ describe('Assets.loadGroup — remote group', () => {});});+describe('a remote group with no CDN root ships inside the package', () => {+ // The cook staged the bytes under `remote/<group>/…` and there is no origin+ // to fetch from, so where they are is the REALM's question — the manifest's+ // address is the authored name, which the package does not carry.+ const PACKAGED: AddressableManifest = {+ version: '2.0',+ revision: 'rev-1',+ groups: {+ cdn: {+ bundleMode: 'remote',+ labels: [],+ assets: {+ 'uuid-1': {+ path: 'remote/cdn/assets/cdn/art.ktx2.bin',+ address: 'assets/cdn/art.png',+ type: 'texture', size: 10, labels: [],+ },+ },+ },+ },+ } as AddressableManifest;++ /** What every packaged realm installs: any spelling → the staged path. */+ const packagedResolver = (ref: string): string => {+ const key = ref.replace(/^@uuid:/, '');+ return key === 'uuid-1' || key === 'assets/cdn/art.png'+ ? 'remote/cdn/assets/cdn/art.ktx2.bin'+ : ref;+ };++ it('loads the staged path, whichever spelling names it', () => {+ const assets = createAssets(backendServing());+ assets.setManifest(PACKAGED);+ assets.setAssetRefResolver(packagedResolver);+ // No setRemoteRoot: this build ships the bytes and has no CDN.++ // The scene's field is rewritten to the authored path at load, so this is+ // the spelling the texture actually asks for on a device.+ expect(assets.resolveLoadPath('assets/cdn/art.png')).toBe('remote/cdn/assets/cdn/art.ktx2.bin');+ expect(assets.resolveLoadPath('@uuid:uuid-1')).toBe('remote/cdn/assets/cdn/art.ktx2.bin');+ });++ it('still goes to the CDN once a root is set', () => {+ const assets = createAssets(backendServing());+ assets.setManifest(PACKAGED);+ assets.setAssetRefResolver(packagedResolver);+ assets.setRemoteRoot('https://cdn.example.com');++ expect(assets.resolveLoadPath('assets/cdn/art.png'))+ .toBe('https://cdn.example.com/remote/cdn/assets/cdn/art.ktx2.bin');+ });+});+/** A cdn manifest whose one asset is REF-BOUND — a slot, not a handle. */function cdnSlotManifest(hash: string, revision: string): AddressableManifest {return {