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(export): a 分包 that did not load says which one and why

esenginee6b385828c86
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 601935d95..d0c5667de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Added
+- **When a 分包 will not come down, the package says which one and why.** The generated entry logged the vendor's error object, which reaches a device's console as `[object Object]` — the one place you get to look. It is stringified now, and the headless launcher can be told to refuse a named 分包 (`--fail-subpackage`) so the path a bad network takes is something a build can be run against rather than waited for.
+
- **A package whose engine ships in a 分包 now starts.** Its generated entry called the host's loading indicator on its first line without checking the host has one — and that call is optional in the API — so on a host that does not implement it the game died before reaching `loadSubpackage`. Every indicator call in a generated entry is guarded now; a progress message must never be what takes a boot down.
- **A group that failed to load says so instead of handing back an empty bundle.** `Assets.loadGroup` settled every asset and returned whatever survived, so a subpackage that downloaded but staged nothing — or a CDN answering 404 — read exactly like a group that was always empty. It now names the assets that failed, the way a scene preload already did.
diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.ts
index 532997bc5..2d435ad23 100644
--- a/pipeline/src/export/miniGameExportProfile.ts
+++ b/pipeline/src/export/miniGameExportProfile.ts
@@ -134,7 +134,10 @@ ${boot.split('\n').map((l) => (l ? ` ${l}` : l)).join('\n')}
},
fail(err) {
try { __g.hideLoading && __g.hideLoading(); } catch (e) {}
- console.error('[estella] the engine subpackage ${ctx.engineSubpackage} did not load — the game cannot start', err);
+ // Stringified: a vendor hands back an object, and a console line reading
+ // "[object Object]" is the one place a device gives you to look.
+ var __why = ''; try { __why = JSON.stringify(err); } catch (e) { __why = String(err); }
+ console.error('[estella] the engine subpackage ${ctx.engineSubpackage} did not load — the game cannot start: ' + __why);
},
});
// Optional on the host: a version without it leaves the 0% notice up, which is
diff --git a/tools/launchers/launch-minigame.mjs b/tools/launchers/launch-minigame.mjs
index 1213336c3..a7475a819 100644
--- a/tools/launchers/launch-minigame.mjs
+++ b/tools/launchers/launch-minigame.mjs
@@ -16,6 +16,7 @@
* --settle <n> frames to let run before capturing (default 30)
* --timeout <ms> how long to wait for the first frame (default 30000)
* --input <json> drive it, same spec as launch-export
+ * --fail-subpackage <name> the host refuses that 分包, to see what it does
*/
import { app, BrowserWindow } from 'electron';
import http from 'node:http';
@@ -53,6 +54,8 @@ const H = Number(flag('h', '360'));
const SETTLE = Number(flag('settle', '30'));
const TIMEOUT = Number(flag('timeout', '30000'));
const INPUT = flag('input', '');
+/** Make the host refuse this 分包, to see what the package does about it. */
+const FAIL_SUBPACKAGE = flag('fail-subpackage', '');
const MIME = {
'.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm',
@@ -118,7 +121,7 @@ async function main() {
}
JSON.parse(readFileSync(manifest, 'utf8')); // a manifest the vendor cannot parse is a dead package
- const server = await serve(DIR, HOST_PAGE(entry));
+ const server = await serve(DIR, HOST_PAGE(entry, FAIL_SUBPACKAGE || null));
const base = `http://127.0.0.1:${server.address().port}/`;
const win = new BrowserWindow({
@@ -128,8 +131,12 @@ async function main() {
const errors = [];
const stop = onRendererConsole(win.webContents, (msg) => {
- if (/\[minigame\] boot failed|uncaught|is not a function|no such file/i.test(msg)) errors.push(msg.slice(0, 400));
- if (msg.startsWith('[minigame]') || msg.startsWith('[engine]')) console.log(` ${msg}`);
+ // `[estella]` is the PACKAGE's own voice — the generated entry says why a 分包
+ // did not come down, which is the diagnosis a silent black frame is missing.
+ if (/\[minigame\] boot failed|\[estella\]|uncaught|is not a function|no such file/i.test(msg)) {
+ errors.push(msg.slice(0, 400));
+ }
+ if (/^\[(minigame|engine|estella)\]/.test(msg)) console.log(` ${msg}`);
});
win.webContents.on('render-process-gone', (_e, d) => errors.push(`render process gone: ${d.reason}`));
diff --git a/tools/launchers/minigameHost.mjs b/tools/launchers/minigameHost.mjs
index 8ed3ecf9d..4e602775a 100644
--- a/tools/launchers/minigameHost.mjs
+++ b/tools/launchers/minigameHost.mjs
@@ -18,8 +18,14 @@
* fails when the contract grows a member the shim has not got.
*/
-/** The page source; `BASE` is substituted with the served root. */
-export const HOST_PAGE = (entry) => `<!doctype html>
+/**
+ * The page source; `BASE` is substituted with the served root.
+ *
+ * `failSubpackage` makes `loadSubpackage` REFUSE that root: a 分包 that will not
+ * come down is a failure a game has to survive, and a stand-in that always
+ * succeeds proves only the happy half.
+ */
+export const HOST_PAGE = (entry, failSubpackage = null) => `<!doctype html>
<html><head><meta charset="utf-8"><style>
html,body{margin:0;height:100%;background:#000;overflow:hidden}
canvas{display:block}
@@ -130,7 +136,14 @@ export const HOST_PAGE = (entry) => `<!doctype html>
onUnhandledRejection: noop, offUnhandledRejection: noop,
onShow: noop, onHide: noop, offShow: noop, offHide: noop,
onWindowResize: noop, offWindowResize: noop,
- loadSubpackage: (o) => { o.success && o.success(); o.complete && o.complete(); },
+ loadSubpackage: (o) => {
+ if (o && o.name === ${JSON.stringify(failSubpackage)}) {
+ o.fail && o.fail({ errMsg: 'loadSubpackage:fail (injected)' });
+ o.complete && o.complete();
+ return;
+ }
+ o.success && o.success(); o.complete && o.complete();
+ },
// Storage is real (localStorage), not a stub: a game that saves on boot and
// reads it back would otherwise take the silent path and look fine.
getStorageSync: (k) => { const v = localStorage.getItem(k); return v === null ? '' : JSON.parse(v); },
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 826afc398..ef191de3c 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(export): a 分包 that did not load says which one and why':
+ { note: 'When a 分包 will not come down, the package says which one and why.' },
'fix(export): a progress notice is never what takes a mini-game boot down':
{ note: 'A package whose engine ships in a 分包 now starts.' },
'fix(assets): a group load names what failed instead of returning an empty bundle':