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.

test(scene): a third teardown door has to say that it is one

esengine424e608c799f
diff --git a/sdk/src/scene/sceneManager.ts b/sdk/src/scene/sceneManager.ts
index 9fe18f06b..85834c7a8 100644
--- a/sdk/src/scene/sceneManager.ts
+++ b/sdk/src/scene/sceneManager.ts
@@ -258,6 +258,13 @@ export class SceneManagerState {
this.app_ = app;
}
+ /**
+ * Forget the scenes while the caller keeps the World.
+ *
+ * scene-teardown: NOT the shared protocol. Entities stay, so what they still
+ * render must not be released under them — and a dropped instance therefore
+ * keeps its receipts and systems. No caller in this repo says if that is right.
+ */
reset(): void {
for (const instance of this.scenes_.values()) {
for (const id of instance.drawCallbacks.keys()) {
diff --git a/tools/check-scene-teardown.mjs b/tools/check-scene-teardown.mjs
index 142924795..cafecfea1 100644
--- a/tools/check-scene-teardown.mjs
+++ b/tools/check-scene-teardown.mjs
@@ -10,7 +10,9 @@
* unregistered no draw callbacks and unbound no post-process.
*
* 1. `unload` and `rollbackFailedLoad_` perform no teardown of their own —
- * both go through disposeSceneOwnedState_.
+ * both go through disposeSceneOwnedState_. A third door that tears scenes
+ * down its own way (reset) has to SAY so, with the reason: a silent copy
+ * is how the second one came to be missing four steps.
* 2. The protocol still performs all of them. Emptying a collection is not
* giving its contents back: dropping the `removeSystem` loop while keeping
* `systemIds.length = 0` leaves the systems running and looks tidy.
@@ -38,7 +40,8 @@ const stripComments = (text) =>
.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '))
.replace(/\/\/[^\n]*/g, '');
-const src = stripComments(readFileSync(path.join(ROOT, FILE), 'utf8'));
+const raw = readFileSync(path.join(ROOT, FILE), 'utf8');
+const src = stripComments(raw);
/**
* One method body, braces balanced. Anchored at the member declaration: matching
@@ -90,6 +93,17 @@ for (const name of ['unload', 'rollbackFailedLoad_']) {
}
}
+// --- 1b. a door that deliberately differs says so --------------------------
+const reset = methodBody('reset');
+if (!reset) {
+ findings.push(`${FILE} reset() is gone — this guard is reading the wrong file.`);
+ // The marker is read from the RAW text: it is a comment, and `src` has had
+ // its comments taken out.
+} else if (!/\bdisposeSceneOwnedState_\s*\(/.test(reset.text)
+ && !/scene-teardown:\s*\S/.test(raw.split('\n').slice(Math.max(0, reset.line - 9), reset.line - 1).join('\n'))) {
+ findings.push(`${FILE}:${reset.line} reset() drops scenes without the shared teardown and without saying why — write \`// scene-teardown: <why>\` above it, or go through disposeSceneOwnedState_.`);
+}
+
// --- 2. and the protocol still performs every one of them ------------------
for (const op of TEARDOWN_OPS) {
if (op.test(protocol)) continue;