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
fix(native): a native build reports its draws, and what the debug channel costs it
esenginee7a05a0eaa31
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2d70bce5c..f09c82e31 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,10 @@ published separately; it ships inside the editor.## [Unreleased]+### Fixed++- A native development build's Profiler shows its draw calls, triangles, sprites and VRAM, and what the debug channel costs it: all read 0 on a native build.+## [0.73.0] - 2026-09-25### Addeddiff --git a/sdk/src/app/profileRecorder.ts b/sdk/src/app/profileRecorder.tsindex 5acf01ffe..95924b25a 100644--- a/sdk/src/app/profileRecorder.ts+++ b/sdk/src/app/profileRecorder.ts@@ -5,6 +5,7 @@*/import type { App, Plugin } from './app';import { Renderer } from '../render/renderer';+import { engineApi } from '../ecs/bridge/engineApi';import {PROFILE_CAPTURE_VERSION,type CaptureSource,@@ -82,7 +83,7 @@ export class ProfileRecorder {this.frames_.length = 0;this.seq_ = 0;this.app_.enableStats();- this.app_.wasmModule?.engine_setCpuProfiling?.(true);+ engineApi(this.app_)?.engine_setCpuProfiling?.(true);this.recording_ = true;this.detach_ = this.app_.onFrameEnd((dtMs) => this.capture_(dtMs));}@@ -93,7 +94,7 @@ export class ProfileRecorder {this.recording_ = false;this.detach_?.();this.detach_ = null;- this.app_.wasmModule?.engine_setCpuProfiling?.(false);+ engineApi(this.app_)?.engine_setCpuProfiling?.(false);}/** Throw away what has been recorded, keeping the recorder running. */@@ -118,7 +119,7 @@ export class ProfileRecorder {private capture_(dtMs: number): void {const costs = this.app_.getFrameCosts();if (!costs) return;- const m = this.app_.wasmModule;+ const m = engineApi(this.app_);const render = Renderer.getStats();const frame: CapturedFrame = {id: this.seq_++,@@ -132,7 +133,7 @@ export class ProfileRecorder {triangles: render.triangles,entities: this.app_.getEntityCount(),memory: {- wasmBytes: m?.HEAPU8?.byteLength ?? 0,+ wasmBytes: this.app_.wasmModule?.HEAPU8?.byteLength ?? 0,jsHeapBytes: jsHeapBytes(),vramBytes: m?.renderer_getTextureBytes?.() ?? 0,},diff --git a/sdk/src/platform/native/adapter.ts b/sdk/src/platform/native/adapter.tsindex b18411dda..804ba5728 100644--- a/sdk/src/platform/native/adapter.ts+++ b/sdk/src/platform/native/adapter.ts@@ -133,7 +133,7 @@ export class NativePlatformAdapter implements PlatformAdapter {}now(): number {- return this.bridge_.now?.() ?? Date.now();+ return this.bridge_.now?.() ?? (typeof performance !== 'undefined' ? performance.now() : Date.now());}devicePixelRatio(): number {diff --git a/sdk/src/platform/native/bridge.ts b/sdk/src/platform/native/bridge.tsindex 9b69a5708..c95475939 100644--- a/sdk/src/platform/native/bridge.ts+++ b/sdk/src/platform/native/bridge.ts@@ -217,7 +217,8 @@ export interface NativeBridge {steam?: NativeSteamBridge;devicePixelRatio(): number;- /** High-resolution clock. Optional — falls back to `Date.now()`. */+ /** High-resolution clock. Optional — falls back to the host's `performance.now()`,+ * then `Date.now()`, whose whole milliseconds read sub-millisecond spans as 0. */now?(): number;/** Host UI language ('zh-CN', 'en-US', …). Optional — falls back to 'en'. */language?(): string;diff --git a/sdk/src/runtime/frameStats.ts b/sdk/src/runtime/frameStats.tsindex 46765e3aa..e3f27c8f6 100644--- a/sdk/src/runtime/frameStats.ts+++ b/sdk/src/runtime/frameStats.ts@@ -6,6 +6,7 @@* them — the same answer from its Play realm and from a device.*/import type { App, FrameCosts } from '../app/app';+import { engineApi } from '../ecs/bridge/engineApi';export interface FrameStatsReport {phases: Record<string, number>;@@ -30,7 +31,7 @@ function jsonMap(json: string | undefined): Record<string, number> {}export function frameStatsReport(app: App): FrameStatsReport {- const m = app.wasmModule;+ const m = engineApi(app);return {phases: Object.fromEntries(app.getPhaseTimings() ?? []),costs: app.getFrameCosts(),@@ -42,7 +43,7 @@ export function frameStatsReport(app: App): FrameStatsReport {cppScopes: jsonMap(m?.engine_getCpuScopes?.()),cppCounters: jsonMap(m?.engine_getCounters?.()),gpuScopes: jsonMap(m?.engine_getGpuScopes?.()),- wasmBytes: m?.HEAPU8?.byteLength ?? 0,+ wasmBytes: app.wasmModule?.HEAPU8?.byteLength ?? 0,vramBytes: m?.renderer_getTextureBytes?.() ?? 0,};}diff --git a/sdk/tests/native-adapter.test.ts b/sdk/tests/native-adapter.test.tsindex 232adee79..d843b50e2 100644--- a/sdk/tests/native-adapter.test.ts+++ b/sdk/tests/native-adapter.test.ts@@ -135,6 +135,13 @@ describe('NativePlatformAdapter (mock bridge)', () => {expect(platformLanguage()).toBe('zh-CN');});+ it('without a host clock, times sub-millisecond spans instead of reading them as 0', () => {+ const { now: _, ...clockless } = env.bridge;+ const bare = installNativePlatform(clockless);+ vi.spyOn(performance, 'now').mockReturnValueOnce(100.25).mockReturnValueOnce(100.5);+ expect(bare.now() - bare.now()).toBe(-0.25);+ });+it('dispatches pushed native input, synthesizing the primary pointer', () => {const cb = makeInputCallbacks();adapter.bindInputEvents(cb);diff --git a/sdk/tests/native-frame-stats.test.ts b/sdk/tests/native-frame-stats.test.tsnew file mode 100644index 000000000..3755442a8--- /dev/null+++ b/sdk/tests/native-frame-stats.test.ts@@ -0,0 +1,65 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file native-frame-stats.test.ts — a device with no wasm module still reports+ * what its engine counted.+ *+ * A native build answers the engine's counters through the host's bindings, not a+ * module; reading `app.wasmModule` there reported zero draws for a frame the Frame+ * Debugger captured ten draws from.+ */+import { afterEach, describe, expect, it, vi } from 'vitest';+import { App } from '../src/app/app';+import { Schedule, defineSystem } from '../src/ecs/system';+import { setNativeEngineApi } from '../src/ecs/bridge/engineApi';+import { frameStatsReport } from '../src/runtime/frameStats';+import { ProfileRecorder } from '../src/app/profileRecorder';++function nativeEngine() {+ return {+ renderer_getDrawCalls: () => 10,+ renderer_getTriangles: () => 36,+ renderer_getSprites: () => 7,+ renderer_getGpuTimeMs: () => 1.5,+ renderer_getTextureBytes: () => 4096,+ engine_getCpuScopes: () => JSON.stringify({ 'render.submit': 0.8 }),+ engine_getCounters: () => JSON.stringify({ batches: 3 }),+ engine_getGpuScopes: () => JSON.stringify({ main: 1.2 }),+ engine_setCpuProfiling: vi.fn(),+ };+}++afterEach(() => setNativeEngineApi(null));++describe('frame stats on a device with no wasm module', () => {+ it('reads the counters from the native engine', () => {+ setNativeEngineApi(nativeEngine());+ const report = frameStatsReport(App.new());++ expect(report).toMatchObject({+ drawCalls: 10, triangles: 36, sprites: 7, gpuMs: 1.5, vramBytes: 4096,+ cppScopes: { 'render.submit': 0.8 },+ cppCounters: { batches: 3 },+ gpuScopes: { main: 1.2 },+ wasmBytes: 0,+ });+ });++ it('a profile recording turns on and reads the native engine too', async () => {+ const engine = nativeEngine();+ setNativeEngineApi(engine);+ const app = App.new();+ app.addSystemToSchedule(Schedule.Update, defineSystem([], () => {}, { name: 'Worker' }));+ const rec = new ProfileRecorder(app);++ rec.start();+ await app.tick(1 / 60);+ rec.stop();++ expect(engine.engine_setCpuProfiling.mock.calls).toEqual([[true], [false]]);+ const frame = rec.take().frames[0];+ expect(frame.gpuMs).toBe(1.5);+ expect(frame.memory?.vramBytes).toBe(4096);+ expect(frame.counters).toEqual({ batches: 3 });+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex d36ba274b..bae944645 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1142,4 +1142,6 @@ export const NOTED = {{ note: 'A native Android app can reach the network: its manifest never asked for it, so a remote group\'s assets, hot updates and the debug channel all failed on Android. A development build also allows plain http (a LAN CDN); a shipping build is held to https, and the export warns when its CDN is http.' },'feat(native): a native build\'s frame can be captured and replayed':{ note: 'A connected native build\'s frame can be captured and replayed.' },+ 'fix(native): a native build reports its draws, and what the debug channel costs it':+ { note: 'A native development build\'s Profiler shows its draw calls, triangles, sprites and VRAM, and what the debug channel costs it: all read 0 on a native build.' },};