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(debug): device_screenshot reads a native build's frame back

yhh958b15a54f22
diff --git a/desktop b/desktop
index 591d8c415..9ee210d7e 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 591d8c41555b42070dcc0324b54b3270cec3c2f0
+Subproject commit 9ee210d7e7b00284ab7b0e85a53879490265ba71
diff --git a/sdk/src/app/app.ts b/sdk/src/app/app.ts
index 8480feca7..eafa36b64 100644
--- a/sdk/src/app/app.ts
+++ b/sdk/src/app/app.ts
@@ -2009,6 +2009,16 @@ export function graphicsPathOf(app: App): GraphicsPath | null {
return surfaces.get(app)?.graphics ?? null;
}
+/**
+ * Tell @p app the size its host draws at — what a host that builds its App
+ * without {@link createWebApp} (the native core) does, so frame read-back and
+ * anything else asking {@link surfaceSizeOf} gets the same answer on every core.
+ * @internal
+ */
+export function setAppSurfaceSize(app: App, size: () => { width: number; height: number }): void {
+ surfaces.set(app, { graphics: surfaces.get(app)?.graphics ?? null, size });
+}
+
/** The size the engine draws at, as its host reports it; null when the host did not say. */
export function surfaceSizeOf(app: App): { width: number; height: number } | null {
return surfaces.get(app)?.size?.() ?? null;
diff --git a/sdk/src/ecs/bridge/nativeRuntime.ts b/sdk/src/ecs/bridge/nativeRuntime.ts
index 846e8f4ee..cd6046e2a 100644
--- a/sdk/src/ecs/bridge/nativeRuntime.ts
+++ b/sdk/src/ecs/bridge/nativeRuntime.ts
@@ -10,7 +10,7 @@
// authoring runs in the JS engine, writing the native C++ ECS, which the native
// host renders. No wasm module: entity generations fall back to World's JS path.
-import { App } from '../../app/app';
+import { App, setAppSurfaceSize } from '../../app/app';
import { World } from '../world';
import { inputPlugin } from '../../input/input';
import { prefabsPlugin } from '../../prefab/prefabServer';
@@ -241,6 +241,9 @@ function installNativeRenderer(app: App, scope: Record<string, unknown>): void {
// The viewport is read per frame, so a rotation reaches the projection without
// anyone pushing a resize event.
app.addPlugin(cameraPlugin(() => nativeSurfaceSize(scope)));
+ // The same answer for anyone else who asks — the debug channel's screenshot
+ // read nothing here and reported a host that "did not say what size it draws at".
+ setAppSurfaceSize(app, () => nativeSurfaceSize(scope));
// Tell the host to stop drawing its fallback frame: from here the pipeline
// above opens and closes every pass, and a second one would clear over it.
scope[HOST_FLAGS.ownsFrame] = true;
diff --git a/sdk/src/runtime/debugChannel.ts b/sdk/src/runtime/debugChannel.ts
index 194e5a196..364106da9 100644
--- a/sdk/src/runtime/debugChannel.ts
+++ b/sdk/src/runtime/debugChannel.ts
@@ -16,7 +16,9 @@ import { getPlatform, platformNow } from '../platform/base';
import type { PlatformSocket } from '../platform/types';
import type { NextFrame } from '../render/frameCapture';
import { captureFrameReport, captureEngineOf, replayFrameDraw, type FrameReplayImage } from '../render/frameDebugReport';
-import { captureFramePixels } from '../render/framePixels';
+import { captureFramePixels, canCaptureFramePixels } from '../render/framePixels';
+import { engineApi } from '../ecs/bridge/engineApi';
+import type { ESEngineModule } from '../wasm';
import { log } from '../util/logger';
import { Assets } from '../asset/AssetPlugin';
import { Lifecycle } from '../ecs/lifecycle';
@@ -215,10 +217,13 @@ export function startDebugChannel(config: DebugChannelConfig): void {
}
if (q.kind === 'screen') {
const size = surfaceSizeOf(game);
- if (!size || !game.wasmModule) throw new Error('this build cannot read its frame back: its host did not say what size it draws at');
+ if (!size) throw new Error('this build cannot read its frame back: its host did not say what size it draws at');
+ // The core through engineApi, not wasmModule: a device has no wasm
+ // module, and its engine answers the same read-back entry points.
+ const module = engineApi(game) as unknown as ESEngineModule | null;
+ if (!module || !canCaptureFramePixels(module)) throw new Error('this build cannot read its frame back: its engine has no frame read-back');
// Asked for inside a frame, before it is handed to the page: GL reads
// the default framebuffer on the spot, and once presented it is cleared.
- const module = game.wasmModule;
const shot = await new Promise<Awaited<ReturnType<typeof captureFramePixels>>>((resolve, reject) => {
const off = game.onFrameEnd(() => {
off();