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(camera): CameraView and PresentedCameraView are published on the native core too

yhh7254502f3002
diff --git a/sdk/src/app/corePlugin.ts b/sdk/src/app/corePlugin.ts
index 2ba8a9aa3..f9bb603e9 100644
--- a/sdk/src/app/corePlugin.ts
+++ b/sdk/src/app/corePlugin.ts
@@ -13,7 +13,6 @@ import { initGeometryAPI, shutdownGeometryAPI } from '../render/geometry';
import { initPostProcessAPI, shutdownPostProcessAPI } from '../postprocess';
import { initRendererAPI, shutdownRendererAPI } from '../render/renderer';
import { initGLDebugAPI, shutdownGLDebugAPI } from '../render/glDebug';
-import { CameraView, CameraViewAPI, PresentedCameraView, presentedCameraView } from '../camera/Camera';
let offMemoryWarning: (() => void) | null = null;
@@ -39,11 +38,6 @@ export const corePlugin: Plugin = {
initPostProcessAPI(module);
initRendererAPI(module);
initGLDebugAPI(module);
- app.insertResource(CameraView, new CameraViewAPI(app));
- // Published beside it, not instead of it: a system inside the frame
- // wants the camera being resolved, and an overlay on the picture wants
- // the one that drew it. Two questions, so two resources.
- app.insertResource(PresentedCameraView, presentedCameraView(app));
// One integer a frame, in the core rather than in whoever drives the
// recovery: a host without the asset layer loses its device too, and a
// game learns the picture came back from one place either way.
diff --git a/sdk/src/camera/CameraPlugin.ts b/sdk/src/camera/CameraPlugin.ts
index 3f86efe34..21e0cafd3 100644
--- a/sdk/src/camera/CameraPlugin.ts
+++ b/sdk/src/camera/CameraPlugin.ts
@@ -17,6 +17,7 @@ import type { World } from '../ecs/world';
import type { Entity } from '../types';
import { UICameraInfo, type UICameraData } from '../ui/core/ui-camera-info';
import { CameraCommit, cameraCommitChanged } from './CameraCommit';
+import { CameraView, CameraViewAPI, PresentedCameraView, presentedCameraView } from './Camera';
import { ScreenLayout, screenLayoutRect, screenProjection } from '../ui/core/screen-layout';
import { ScreenOverlay } from '../ui/core/screen-overlay';
import { ProjectionType, SceneOwner, ClearFlags } from '../ecs/component';
@@ -834,6 +835,14 @@ export function cameraPlugin(
// games call setViewTarget(app, entity, {time, curve}) to blend, or
// shakeCamera(app, {...}) to shake. Fresh state (own arrays) per App.
app.insertResource(CameraDirector, createDirectorState());
+ // The camera queries belong to the plugin that resolves the camera,
+ // not to one core's bootstrap: the native core never runs corePlugin,
+ // and publishing them there left both null on every device.
+ app.insertResource(CameraView, new CameraViewAPI(app));
+ // Published beside it, not instead of it: a system inside the frame
+ // wants the camera being resolved, and an overlay on the picture wants
+ // the one that drew it. Two questions, so two resources.
+ app.insertResource(PresentedCameraView, presentedCameraView(app));
const viewport = getViewportSize ?? (() => {
const dpr = platformDevicePixelRatio();
diff --git a/sdk/tests/native-text.test.ts b/sdk/tests/native-text.test.ts
index 57d3b7049..ffc8e26b9 100644
--- a/sdk/tests/native-text.test.ts
+++ b/sdk/tests/native-text.test.ts
@@ -12,6 +12,7 @@
* collect and flush, close it. That order IS the contract with the host, which
* only presents afterwards.
*/
+import { CameraView, CameraViewAPI, PresentedCameraView } from '../src/camera/Camera';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createNativeApp } from '../src/ecs/bridge/nativeRuntime';
import { shutdownResourceManager } from '../src/wasm/resourceManager';
@@ -179,6 +180,17 @@ function buildScene(app: ReturnType<typeof createNativeApp>, setScene: (canvas:
}
describe('a frame on the native core', () => {
+ it('publishes the camera queries the web publishes', async () => {
+ const host = makeHostScope();
+ const app = createNativeApp(makeBridge(host.scope), host.scope);
+ await app.tick(0);
+ // A game reads these the same way on both cores; null on a device was a
+ // per-frame throw the editor's Play never showed.
+ expect(app.getResource(CameraView)).toBeInstanceOf(CameraViewAPI);
+ expect(app.getResource(PresentedCameraView)).toBeInstanceOf(CameraViewAPI);
+ app.quit({ keepRenderer: true });
+ });
+
it('keeps bitmap geometry aligned with the native viewport after DPR changes', async () => {
const host = makeHostScope();
let density = 1;