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(editor): time out a wedged play-realm prepare instead of hanging forever

yhh82d96af34f33
diff --git a/desktop/src/engine/PlayRealm.ts b/desktop/src/engine/PlayRealm.ts
index fe77e0616..17b43551b 100644
--- a/desktop/src/engine/PlayRealm.ts
+++ b/desktop/src/engine/PlayRealm.ts
@@ -27,6 +27,22 @@ import type { PlayOutbound, PlayInbound, PlayPayload, PlaySnapshot, PlayStatsRep
export type { PlayPayload, PlaySnapshot } from './playProtocol';
+/** A cold first Play stages the SDK + wasm and bundles the project scripts (a few
+ * seconds). Cap the wait so a WEDGED prepare step — e.g. a hung esbuild service —
+ * surfaces as a retryable play error instead of an indefinite "Starting game…". */
+const PREPARE_TIMEOUT_MS = 30_000;
+
+/** Reject `p` if it hasn't settled within `ms`; otherwise pass its result through. */
+function withTimeout<T>(p: Promise<T>, ms: number, message: string): Promise<T> {
+ return new Promise<T>((resolve, reject) => {
+ const timer = setTimeout(() => reject(new Error(message)), ms);
+ p.then(
+ (v) => { clearTimeout(timer); resolve(v); },
+ (e) => { clearTimeout(timer); reject(e); },
+ );
+ });
+}
+
export interface PlayRealmSnapshot {
playing: boolean;
ready: boolean;
@@ -128,7 +144,11 @@ export class PlayRealmInstance {
}
try {
- const realm = await window.estella.project.preparePlayRealm();
+ const realm = await withTimeout(
+ window.estella.project.preparePlayRealm(),
+ PREPARE_TIMEOUT_MS,
+ t('proj.playPrepareTimeout'),
+ );
if (this.id === 0) bootProfiler.mark('preparePlayRealm (stage + esbuild)');
if (!realm.ok) {
this.set({ error: realm.errors[0] ?? t('proj.playPrepareFailed') });
diff --git a/desktop/src/i18n/messages/project.ts b/desktop/src/i18n/messages/project.ts
index 52a19fe4c..096b3d6d9 100644
--- a/desktop/src/i18n/messages/project.ts
+++ b/desktop/src/i18n/messages/project.ts
@@ -125,5 +125,9 @@ export const projectMessages = defineMessages({
// — Play realm (Game panel overlay fallbacks) —
'proj.playPrepareFailed': { en: 'failed to prepare play realm', zh: '无法准备游戏运行环境' },
+ 'proj.playPrepareTimeout': {
+ en: 'Preparing the game timed out (the script bundler may be wedged). Press Play to retry; restart the editor if it persists.',
+ zh: '准备游戏运行环境超时(脚本打包器可能卡死)。请再次点击运行重试;若仍然如此,请重启编辑器。',
+ },
'proj.playRealmError': { en: 'play realm error', zh: '游戏运行环境错误' },
});