Skip to content

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.

fix(asset): EmbeddedBackend accepts an already-resolved data: URL

yhhdd87ad16e624
diff --git a/sdk/src/asset/Backend.ts b/sdk/src/asset/Backend.ts
index 0cbfaf523..8b5f8a841 100644
--- a/sdk/src/asset/Backend.ts
+++ b/sdk/src/asset/Backend.ts
@@ -111,6 +111,14 @@ export class EmbeddedBackend implements Backend {
}
private getDataUrl(path: string): string {
+ // Accept an already-resolved data: URL, not only a map key. The asset loader
+ // fetches typed text/binary through `fetchText(resolveUrl(ref))` — idempotent
+ // for HttpBackend (resolveUrl of an absolute URL is a no-op). Here resolveUrl
+ // has already returned the data URL, so a second lookup keyed by that URL
+ // would miss and throw. Pass a data: URL straight through so resolve-then-fetch
+ // is idempotent for the embedded backend too (this is what broke embedded
+ // tilemap/material/tileset loading in playable builds).
+ if (path.startsWith('data:')) return path;
const dataUrl = this.assets_.get(path);
if (!dataUrl) {
throw new Error(`EmbeddedBackend: asset not found: ${path}`);
diff --git a/sdk/tests/asset-backend.test.ts b/sdk/tests/asset-backend.test.ts
index 70978a0b9..e28e0b1c5 100644
--- a/sdk/tests/asset-backend.test.ts
+++ b/sdk/tests/asset-backend.test.ts
@@ -57,4 +57,14 @@ describe('EmbeddedBackend', () => {
it('resolveUrl returns path as-is for missing assets', () => {
expect(backend.resolveUrl('missing.txt')).toBe('missing.txt');
});
+
+ // Regression: typed text/binary assets load via `fetchText(resolveUrl(ref))`
+ // (idempotent for HttpBackend). resolveUrl already returns the data URL here, so
+ // fetch must accept it instead of re-looking it up as a key — otherwise embedded
+ // tilemaps/materials fail in playable builds with "asset not found: data:...".
+ it('fetch is idempotent under resolveUrl (resolve-then-fetch)', async () => {
+ expect(await backend.fetchText(backend.resolveUrl('config.txt'))).toBe('hello world');
+ const bytes = new Uint8Array(await backend.fetchBinary(backend.resolveUrl('data.bin')));
+ expect(bytes).toEqual(new Uint8Array([1, 2, 3]));
+ });
});