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(playable): resolve Spine atlas textures from the inlined asset map

yhh77677691d0aa
diff --git a/sdk/src/playableRuntime.ts b/sdk/src/playableRuntime.ts
index d6cb086de..681dbaa37 100644
--- a/sdk/src/playableRuntime.ts
+++ b/sdk/src/playableRuntime.ts
@@ -84,18 +84,27 @@ export async function initPlayableRuntime(config: PlayableRuntimeConfig): Promis
// emit) — the aliases point at the SAME data-URL strings, so path refs cost
// nothing and every consumer below resolves through one map.
const assets = { ...config.assets };
+ const keyToPath: Record<string, string> = {};
for (const [logical, key] of Object.entries(config.assetPathMap ?? {})) {
const data = assets[key];
if (!data) continue;
assets[logical] ??= data;
assets[`/${logical}`] ??= data;
+ // Reverse index (@uuid key → its logical source path); first path wins.
+ keyToPath[key] ??= logical;
}
// Canonical asset source: the shared EmbeddedBackend (data-URLs) + a DOM image
- // decode over the same data-URL. Refs are the map keys (resolveRef = identity).
+ // decode over the same data-URL. `resolveRef` yields a logical PATH (not the
+ // bare @uuid key) so consumers that derive sibling paths from a resolved ref
+ // work — e.g. a Spine atlas names its texture pages by filename, resolved
+ // against the atlas's own directory. This matches the web/manifest runtime's
+ // resolveRef contract; a ref with no known path (or already a path) passes
+ // through, and the backend resolves both spellings off the same aliased map.
const backend = new EmbeddedBackend(assets);
const source: RuntimeAssetSource = {
backend,
+ resolveRef: (ref) => keyToPath[ref] ?? ref,
decodePixels: (path) => loadImagePixels(backend.resolveUrl(path)),
// Map keys are the shippable paths (logical aliases included) — the
// .eslocale discovery filters on extension, so aliases resolve fine.
diff --git a/sdk/src/spine/loadSpineScene.ts b/sdk/src/spine/loadSpineScene.ts
index 192628d78..57c6ea087 100644
--- a/sdk/src/spine/loadSpineScene.ts
+++ b/sdk/src/spine/loadSpineScene.ts
@@ -110,7 +110,9 @@ export async function loadSpineAssets(
const textures = new Map<string, { glId: number; w: number; h: number }>();
for (const texName of texNames) {
- const texPath = atlasDir + '/' + texName;
+ // No dir ⇒ the page name IS the path (never a leading-slash
+ // "/page.png", which resolves to nothing) — matches SpineAssetLoader.
+ const texPath = atlasDir ? atlasDir + '/' + texName : texName;
try {
// The atlas names its pages by AUTHORED filename; a cook may
// have re-encoded (.ktx2) or content-addressed the staged
diff --git a/sdk/tests/playableRuntime.test.ts b/sdk/tests/playableRuntime.test.ts
index ef41d015a..1f2a7e6a3 100644
--- a/sdk/tests/playableRuntime.test.ts
+++ b/sdk/tests/playableRuntime.test.ts
@@ -100,6 +100,27 @@ describe('initPlayableRuntime', () => {
expect(backend.resolveUrl('@uuid:aaaa')).toBe('data:text/plain;base64,QQ==');
});
+ // resolveRef must yield a logical PATH for an embedded @uuid key, not the bare
+ // key: consumers derive sibling paths from a resolved ref (a Spine atlas names
+ // its texture pages by filename, resolved against the atlas's directory).
+ // Regression: an identity resolveRef left the atlas dir empty → "/spineboy.png"
+ // → ERR_FILE_NOT_FOUND on a single-file playable.
+ it('resolveRef expands an embedded @uuid to its logical source path', async () => {
+ const config = createMockConfig({
+ assets: { '@uuid:atlas': 'data:application/octet-stream;base64,QQ==' },
+ assetPathMap: { 'assets/spine/boy.atlas': '@uuid:atlas' },
+ });
+
+ await initPlayableRuntime(config);
+
+ const call = vi.mocked(initRuntime).mock.calls[0][0];
+ const resolveRef = call.source.resolveRef as (r: string) => string;
+ expect(resolveRef('@uuid:atlas')).toBe('assets/spine/boy.atlas');
+ // A ref with no known path (or already a path) passes through unchanged.
+ expect(resolveRef('assets/spine/boy.png')).toBe('assets/spine/boy.png');
+ expect(resolveRef('@uuid:unknown')).toBe('@uuid:unknown');
+ });
+
// A single-file playable makes NO external requests — its `file://` page is a
// null origin whose sibling fetches are CORS-blocked. Video is the newest
// asset channel, so it must resolve through the SAME embedded map as every
diff --git a/sdk/tests/spine-atlas-page-resolve.test.ts b/sdk/tests/spine-atlas-page-resolve.test.ts
index e5505cf6d..b561ad05e 100644
--- a/sdk/tests/spine-atlas-page-resolve.test.ts
+++ b/sdk/tests/spine-atlas-page-resolve.test.ts
@@ -85,6 +85,24 @@ describe('loadSpineAssets resolves atlas page paths through the manifest', () =>
expect(source.decodePixels).toHaveBeenCalledWith('assets/1234abcd.png', false);
});
+ it('derives the page dir from a @uuid atlas ref resolved to its PATH (playable)', async () => {
+ // The playable resolveRef expands @uuid → logical source path; the page
+ // path must come from THAT resolved dir, not the bare @uuid (which gave an
+ // empty dir → "/spineboy.png" → ERR_FILE_NOT_FOUND).
+ const source = makeSource({
+ '@uuid:skel': 'assets/spine/boy.skel',
+ '@uuid:atlas': 'assets/spine/boy.atlas',
+ });
+ await loadSpineAssets({} as never, source, null, [{ skeleton: '@uuid:skel', atlas: '@uuid:atlas' }]);
+ expect(source.decodePixels).toHaveBeenCalledWith('assets/spine/spineboy.png', false);
+ });
+
+ it('a dirless atlas path yields the bare page name, never a leading slash', async () => {
+ const source = makeSource({});
+ await loadSpineAssets({} as never, source, null, [{ skeleton: 'boy.skel', atlas: 'boy.atlas' }]);
+ expect(source.decodePixels).toHaveBeenCalledWith('spineboy.png', false);
+ });
+
it('a KTX2 page in a realm without basis warns and skips, not throws', async () => {
const source = makeSource({ 'assets/spine/spineboy.png': 'assets/spine/spineboy.ktx2' });
const info = await loadSpineAssets({} as never, source, null, PAIR, async () => null);