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
test(ui): the screen's two open contracts get answers, and one gets a gate
esenginee6a756a94ad3
diff --git a/fixtures/scenes/ui-screen-no-camera.esscene b/fixtures/scenes/ui-screen-no-camera.esscenenew file mode 100644index 000000000..e8dc339df--- /dev/null+++ b/fixtures/scenes/ui-screen-no-camera.esscene@@ -0,0 +1,132 @@+{+ "version": 4,+ "name": "A Canvas and NO Camera. The layout authority owes a camera nothing, and this asks whether the PRESENTATION does either: with no camera there is no view to derive a viewport or a layer mask from, only a surface.",+ "entities": [+ {+ "id": 1,+ "name": "Canvas",+ "parent": null,+ "children": [+ 2,+ 3+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {}+ },+ {+ "type": "Canvas",+ "data": {+ "designResolution": {+ "x": 1920,+ "y": 1080+ },+ "scaleMode": 1+ }+ },+ {+ "type": "UINode",+ "data": {}+ }+ ]+ },+ {+ "id": 2,+ "name": "TopLeft",+ "parent": 1,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {}+ },+ {+ "type": "UINode",+ "data": {+ "position": 1,+ "width": {+ "value": 50,+ "unit": 1+ },+ "height": {+ "value": 50,+ "unit": 1+ },+ "insetTop": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "color": {+ "r": 1,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "BottomRight",+ "parent": 1,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {}+ },+ {+ "type": "UINode",+ "data": {+ "position": 1,+ "width": {+ "value": 50,+ "unit": 1+ },+ "height": {+ "value": 50,+ "unit": 1+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ },+ "insetRight": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "color": {+ "r": 0,+ "g": 1,+ "b": 0,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/ui-screen-no-camera.textures.json b/fixtures/scenes/ui-screen-no-camera.textures.jsonnew file mode 100644index 000000000..0967ef424--- /dev/null+++ b/fixtures/scenes/ui-screen-no-camera.textures.json@@ -0,0 +1 @@+{}diff --git a/sdk/src/ui/core/screen-overlay.ts b/sdk/src/ui/core/screen-overlay.tsindex 729dbde3a..e1af6ce4e 100644--- a/sdk/src/ui/core/screen-overlay.ts+++ b/sdk/src/ui/core/screen-overlay.ts@@ -17,9 +17,13 @@* In a shipped frame the projection is {@link screenProjection} over the* whole surface: no camera, no world. The editor's design view is the* one place it is anything else — there the screen box is shown IN the- * scene, zoomed and panned like the content it will sit over, so the- * view's own projection presents it. That is a value this carries, not- * a branch the renderer takes.+ * scene, zoomed and panned like the content it will sit over. That is a+ * value this carries, not a branch the renderer takes.+ *+ * A frame with NO camera still presents: the surface and the design fit+ * are the whole of it (gated by `ui-screen-no-camera`). Needing a camera+ * for the projection, the viewport or the mask would put one back in the+ * screen's path by a side door.*/import { defineResource } from '../../ecs/resource';@@ -45,10 +49,10 @@ export interface ScreenOverlayData {pointerX: number;pointerY: number;/**- * Sorting layers this frame shows, as a bitmask (a Canvas contributes its- * own layer's bit). Which layers a frame shows is a frame-level fact, so the- * overlay reads it here rather than from whichever camera happens to be- * first; where a HUD SITS still owes a camera nothing.+ * Sorting layers this frame shows, as a bitmask — frame-level VISIBILITY+ * POLICY, assembled from the rendering cameras' masks and nothing else about+ * them. It does not make the overlay theirs: the projection, the viewport and+ * the order stay the screen's. With no camera it is every layer.*/layerMask: number;}diff --git a/tools/check-frame-lifecycle.mjs b/tools/check-frame-lifecycle.mjsnew file mode 100644index 000000000..8114b1559--- /dev/null+++ b/tools/check-frame-lifecycle.mjs@@ -0,0 +1,91 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file check-frame-lifecycle.mjs — a frame's resources go back at the FRAME's+ * end, not at a camera's.+ *+ * `GfxDevice::endFrame` is where a backend that borrows the swapchain image for+ * the duration of a frame gives it back. `RenderFrame::begin`/`end` bracket one+ * CAMERA, so releasing there means everything drawn afterwards — a second+ * camera, the screen post stack, the screen overlay — draws into an image the+ * surface has already taken away, and re-acquiring one is an error whose only+ * symptom is a black frame.+ *+ * A pixel gate cannot hold this everywhere: the GL backends implement endFrame+ * as a no-op, so on WebGL2 the wrong ordering looks identical. The behaviour is+ * gated on the second backend (CI runs the pr tier on a real Metal GPU, and+ * ui-screen-post crosses camera → post → overlay → frame end). This is the half+ * that holds on every machine: who is allowed to say the frame is over.+ *+ * node tools/check-frame-lifecycle.mjs+ */+import { readFileSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { listTrackedSources } from './lib/sourceRoots.mjs';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');++/** Source with block and line comments removed. Strings are left as they are —+ * none of the patterns below can appear in one without also being a call. */+function stripComments(text) {+ return text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');+}++/**+ * Where the device may be told the frame is over. `endFrame` is the pair of+ * `beginFrame`; `beginFrame` also closes a frame a host forgot to, which is the+ * forgiving half and belongs to the same owner.+ */+const OWNERS = ['RenderFrame::endFrame', 'RenderFrame::beginFrame'];++/** Which C++ function a line falls inside — `Class::name(` at column zero. */+function enclosingFunction(lines, index) {+ for (let i = index; i >= 0; i--) {+ const m = /^[A-Za-z_][\w:<>,\s*&]*?\b([A-Za-z_]\w*::[A-Za-z_]\w*)\s*\(/.exec(lines[i]);+ if (m) return m[1];+ }+ return '<file scope>';+}++const problems = [];++// ---- 1. Only the frame's own owner releases the frame ----------------------+const { files } = listTrackedSources(['src']);+for (const file of files.filter((f) => f.endsWith('.cpp'))) {+ const lines = readFileSync(path.join(ROOT, file), 'utf8').split('\n');+ for (const [i, line] of lines.entries()) {+ if (!/\bdevice_?\.endFrame\s*\(|\bdevice_->endFrame\s*\(/.test(line)) continue;+ const owner = enclosingFunction(lines, i);+ if (OWNERS.includes(owner)) continue;+ problems.push(`${file}:${i + 1} releases the frame from ${owner}() — `+ + `only ${OWNERS.join(' / ')} may (see this file's header)`);+ }+}++// ---- 2. A host that opens a frame closes it --------------------------------+// Textual, deliberately: the pairing is a fact about a call site and there are+// few. A host that opens without closing holds the image until the next frame.+const HOSTS = ['sdk/src', 'native/host', 'tools/render-host'];+const OPEN = /\b(?:Renderer|pipeline|rf|renderFrame)\.beginFrame\s*\(|->beginFrame\s*\(\s*\)/;+const CLOSE = /\b(?:Renderer|pipeline|rf|renderFrame)\.endFrame\s*\(|->endFrame\s*\(\s*\)/;+const { files: hostFiles, missing } = listTrackedSources(HOSTS);+if (missing.length) {+ console.log(`check-frame-lifecycle: not scanned — ${missing.join(', ')}`);+}+for (const file of hostFiles.filter((f) => /\.(ts|cpp|mjs)$/.test(f))) {+ // Comments stripped first: a commented-out close still reads as a close, and+ // a gate that a `//` can satisfy is worth less than none.+ const text = stripComments(readFileSync(path.join(ROOT, file), 'utf8'));+ // The façade and the pipeline DECLARE both halves rather than driving them.+ if (/renderer\.ts$|renderPipeline\.ts$|nativeRenderer\.ts$/.test(file)) continue;+ if (OPEN.test(text) && !CLOSE.test(text)) {+ problems.push(`${file} opens a frame and never closes it — beginFrame's pair is endFrame`);+ }+}++for (const p of problems) console.log(`✗ ${p}`);+console.log(problems.length === 0+ ? 'check-frame-lifecycle: the frame is released by the frame, and every host that opens one closes it'+ : `check-frame-lifecycle: ${problems.length} finding(s)`);+process.exit(problems.length === 0 ? 0 : 1);diff --git a/tools/gates.mjs b/tools/gates.mjsindex 617db0670..7a3b4e8eb 100644--- a/tools/gates.mjs+++ b/tools/gates.mjs@@ -46,6 +46,7 @@ export const GATES = [{ id: 'gl-boundary', run: 'node tools/check-gl-boundary.mjs' },{ id: 'draw-command-boundary', run: 'node tools/check-draw-command-boundary.mjs' },{ id: 'shadow-pass', run: 'node tools/check-shadow-pass.mjs' },+ { id: 'frame-lifecycle', run: 'node tools/check-frame-lifecycle.mjs' },{ id: 'postfx-aa', run: 'node tools/check-postfx-aa.mjs' },{ id: 'sidemodule-gates', run: 'node tools/check-sidemodule-gates.mjs' },{ id: 'engine-exports', run: 'node tools/check-engine-exports.mjs' },diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex b1683d82f..e00bfd7c7 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -235,6 +235,10 @@ export const SCENES = [// be left in a camera's list while the panel under it moved. Under this// perspective camera such text lands nowhere and the panel comes back blue.{ id: "ui-screen-text", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/ui-screen-text.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/ui-screen-text.textures.json", ESTELLA_VERIFY_W: "640", ESTELLA_VERIFY_H: "360", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\": 0.4, \"y\": 0.5, \"rgb\": [255, 255, 0], \"tol\": 40}, {\"x\": 0.525, \"y\": 0.5, \"rgb\": [255, 255, 0], \"tol\": 40}, {\"x\": 0.5, \"y\": 0.5, \"rgb\": [0, 0, 153], \"tol\": 40}, {\"x\": 0.05, \"y\": 0.5, \"rgb\": [0, 0, 153], \"tol\": 40}]" } },+ // A Canvas and NO Camera. The screen is a surface and a design fit, so neither+ // the layout NOR the presentation needs a view to exist — this is the scene+ // that keeps that a promise rather than an accident of the mask union.+ { id: "ui-screen-no-camera", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SCENE: "/scenes/ui-screen-no-camera.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/ui-screen-no-camera.textures.json", ESTELLA_VERIFY_W: "640", ESTELLA_VERIFY_H: "360", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\": 0.25, \"y\": 0.25, \"rgb\": [255, 0, 0], \"tol\": 30}, {\"x\": 0.75, \"y\": 0.75, \"rgb\": [0, 255, 0], \"tol\": 30}]" } },// Y-sort: same scene twice — mask on flips the overlap to the lower (higher-Y-key) entity; mask off preserves submission order. Both asserted so neither path can silently regress.// Slices of one continuous pattern, each its OWN texture, at a fractional// world-units-per-pixel — seamless art and a non-integer ratio are what a seam