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(runtime): a packaged host looks a resource up in the registry that holds it
esenginede51aa34ce81
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c5d7fd17f..392b1631c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **A packaged game answers "how do I get there?" again.** The host's `pathBetween` — what a driven playthrough and the automation ask for a route — looked `Nav` up in the registry of COMPONENTS when the AI runtimes moved to their own subpath. `Nav` is a resource and has never been in that one, so the lookup answered nothing rather than throwing, every route came back as no route, and a game that walks fine by hand could not be driven anywhere. It asks the resource door now.+- **Pressing Play could kill the session it was starting.** The editor hands the scene to the realm from two doors — directly on a warm re-Play, and on the realm's greeting when it cold-boots — and `start()` claims the scene before it waits on the script rebuild. A greeting that arrived inside that wait went through both doors, and the realm read the second hand-over as a re-Play: it quit the App the first was still booting on, which surfaced a few steps later as a null read and a session that never reached a frame. The scene is handed over once per start now.## [0.70.0] - 2026-09-22diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.tsindex 911bc0231..0bd6825c2 100644--- a/pipeline/src/runtime/gameHost.ts+++ b/pipeline/src/runtime/gameHost.ts@@ -589,8 +589,12 @@ async function boot(): Promise<void> {* game means the route stays right when the level is re-authored.*/pathBetween(fromName: string, toName: string): Array<{ x: number; y: number }> | null {- const nav = optionalDef('Nav');- if (nav === null || !app.hasResource(nav)) return null;+ // Through the App's own by-name door: `Nav` is a RESOURCE, and the+ // component registry optionalDef reads has never held one — asked there+ // it answered null, and every path this host was asked for was no path.+ const nav = app.getResourceByName('Nav') as+ { findWorldPath(a: { x: number; y: number }, b: { x: number; y: number }): Array<{ x: number; y: number }> | null } | undefined;+ if (!nav) return null;const ends = [fromName, toName].map((name) => {const entity = app.world.findEntityByName(name);if (entity === null || !app.world.has(entity, Transform)) return null;@@ -598,8 +602,7 @@ async function boot(): Promise<void> {return { x: p.x, y: p.y };});if (!ends[0] || !ends[1]) return null;- return (app.getResource(nav) as { findWorldPath(a: { x: number; y: number }, b: { x: number; y: number }): Array<{ x: number; y: number }> | null })- .findWorldPath(ends[0], ends[1]);+ return nav.findWorldPath(ends[0], ends[1]);},/*** What the last frame's renderer counted — the work a picture cannot show.diff --git a/pipeline/tests/game-host-lookups.test.ts b/pipeline/tests/game-host-lookups.test.tsnew file mode 100644index 000000000..cc387ca39--- /dev/null+++ b/pipeline/tests/game-host-lookups.test.ts@@ -0,0 +1,53 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file The packaged host looks each name up in the registry that holds it.+ *+ * A package may ship without any given subsystem, so the host reaches its+ * diagnostics by NAME rather than by import. There are two registries behind+ * those names — components and resources — and asking the wrong one answers+ * `null` rather than throwing: `pathBetween` asked the component registry for+ * `Nav`, got nothing, and every route it was asked for came back as no route,+ * which read as a game that could not walk.+ */+import { describe, it, expect } from 'vitest';+import { readFileSync, readdirSync } from 'node:fs';+import path from 'node:path';++const HOST = readFileSync(path.resolve(__dirname, '../src/runtime/gameHost.ts'), 'utf8');++/**+ * Every name `defineResource` was given, which is the only author of what a+ * resource is called. `resourceShapes.ts` holds only the ones a compiled module+ * has to marshal — `Nav` is not in it, so a test that read that list would have+ * been blind to the exact case this exists for.+ */+function resourceNames(dir: string, out: string[] = []): string[] {+ for (const e of readdirSync(dir, { withFileTypes: true })) {+ const p = path.join(dir, e.name);+ if (e.isDirectory()) resourceNames(p, out);+ else if (e.name.endsWith('.ts')) {+ for (const m of readFileSync(p, 'utf8').matchAll(/defineResource\s*(?:<[^>]*>)?\s*\([^)]*?['"]([A-Za-z0-9_]+)['"]\s*\)/g)) {+ out.push(m[1]);+ }+ }+ }+ return out;+}+const RESOURCES = [...new Set(resourceNames(path.resolve(__dirname, '../../sdk/src')))];++/** Every name handed to a COMPONENT-registry lookup in the host. */+function componentLookups(src: string): string[] {+ return [...src.matchAll(/(?:optionalDef|optionalRead\([^,]+,\s*[^,]+,|countOfIn\([^,]+,|optionalEntities\([^,]+,)\s*\(?'([A-Za-z0-9_]+)'/g)]+ .map((m) => m[1]);+}++describe('the packaged host’s by-name lookups', () => {+ it('never asks the component registry for something that is a resource', () => {+ const asked = componentLookups(HOST);+ expect(asked.length, 'no lookups found — the pattern stopped matching the host').toBeGreaterThan(0);+ expect(RESOURCES, 'no defineResource names found — the scan stopped matching').toContain('Nav');+ const resources = asked.filter((n) => RESOURCES.includes(n));+ expect(resources, 'these are resources; ask app.getResourceByName instead').toEqual([]);+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex dbe3e89b7..7afe84b56 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -700,6 +700,8 @@ export const NOTED = {{ internal: "the editor's preview page names the same subpaths it always did" },'fix(settings): the module page reads the same asset table the build installs from':{ note: 'The Engine Modules page no longer calls a module unused that the build then carries.' },+ 'fix(runtime): a packaged host looks a resource up in the registry that holds it':+ { note: 'A packaged game answers "how do I get there?" again.' },'fix(play): the scene is handed to the realm once per start, not once per door':{ note: 'Pressing Play could kill the session it was starting.' },'fix(theme): the size bar reads as a measurement, not as a running state':