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(render): a linear game looks the same on every Play, where from the second on a scene with no effects showed raw linear values

yhh8cadde8155fb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 060d38cf9..992752b5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,7 @@ published separately; it ships inside the editor.
- **An agent's `get_stats` waits out a long frame.** It gave a running game two seconds to answer, so on a machine that takes that long to draw a frame it said the game had stopped.
- **A saved scene reaches a device preview on Linux.** The project watch followed each file's inode, so a file replaced by rename stopped reporting. It watches each folder there now, which also ends the crash when a watched folder was deleted during a scan.
+- **A linear game looks the same on every Play.** From the second Play on, a scene with no post-process effects showed raw linear values, about a third as bright, with nothing in the log. Stopping a game shut down the pipeline that encodes the frame, and nothing brought it back unless the camera had an effect.
- **Water costs a phone half of what it did.** A full-screen sea on a Snapdragon 8 Elite went from 45 ms to 21.5 at full quality, with the same picture. Every lit material on a phone gains part of it: the light loop read all sixteen slots for every pixel, and now stops at the lights there are. A surface can also declare `#pragma lighting direct` to compile out what it never reaches. Water does, so water takes the first sixteen lights only.
- **A quality level can skip every effect there is.** The list was cut at thirty-two and there are forty effects now, so the last ones in name order kept running while the row showed them off.
- **A new material no longer shows the inside of a sphere.** An opaque mesh tests and writes depth whatever its material says, and a new surface material tests depth.
diff --git a/desktop b/desktop
index cab64b053..b863b0796 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit cab64b0538ace0a96a2b946c178e48d07300d3bd
+Subproject commit b863b0796ec55716c10a4fb913718024837d6103
diff --git a/sdk/src/postprocess/PostProcessAPI.ts b/sdk/src/postprocess/PostProcessAPI.ts
index 5f8e0b676..558cffae1 100644
--- a/sdk/src/postprocess/PostProcessAPI.ts
+++ b/sdk/src/postprocess/PostProcessAPI.ts
@@ -66,11 +66,20 @@ export interface HdrFormat {
* ES_ENABLE_POSTPROCESS answers none of these entry points; the plugin checks that
* before calling, which is what makes the narrowing here sound.
*/
+/** Whether the last App shut the pipeline down under a renderer that may have outlived it. */
+let restartOwed = false;
+
export function initPostProcessAPI(engine: NonNullable<EngineApi>): void {
bridge.connect(engine);
module = bridge.module as PostProcessCore;
const heap = engine as unknown as { _malloc?(n: number): number };
if (!hdrPtr && typeof heap._malloc === 'function') hdrPtr = heap._malloc(4 * 4);
+ // The renderer outlives an App on a warm restart, and the last App shut this down. A linear frame is encoded here,
+ // so waiting for a camera with effects to bring it back left every scene without one showing raw linear values.
+ // Only then: on a first boot the renderer starts its own, and starting one before it exists would make a second.
+ const core = module as PostProcessCore;
+ if (restartOwed && hasPostProcessCore(core) && !core.postprocess_isInitialized()) core.postprocess_init(1, 1);
+ restartOwed = false;
}
/** A core built without ES_ENABLE_POSTPROCESS (the lite mini-game engine) has none of these entry points: no chain, nothing to ask. */
@@ -83,7 +92,10 @@ export function shutdownPostProcessAPI(): void {
// Per-App state dies with its App; here we only tear down the shared module.
if (module) {
try {
- if (hasPostProcessCore(module) && module.postprocess_isInitialized()) module.postprocess_shutdown();
+ if (hasPostProcessCore(module) && module.postprocess_isInitialized()) {
+ module.postprocess_shutdown();
+ restartOwed = true;
+ }
} catch (e) {
handleWasmError(e, 'PostProcess.shutdown');
}
diff --git a/sdk/tests/postprocess-warm-restart.test.ts b/sdk/tests/postprocess-warm-restart.test.ts
new file mode 100644
index 000000000..62b4d96ec
--- /dev/null
+++ b/sdk/tests/postprocess-warm-restart.test.ts
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * The pipeline encodes a linear frame for the display, so a new App on a renderer
+ * that outlived the last one must find it running, effects or no effects.
+ */
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { initPostProcessAPI, shutdownPostProcessAPI } from '../src/postprocess/PostProcessAPI';
+
+function core(running: boolean) {
+ const calls: string[] = [];
+ let up = running;
+ return {
+ calls,
+ postprocess_isInitialized: () => up,
+ postprocess_init: () => { calls.push('init'); up = true; return true; },
+ postprocess_shutdown: () => { calls.push('shutdown'); up = false; },
+ };
+}
+
+describe('a new App on a renderer that outlived the last', () => {
+ // What one test owes must not reach the next: a core with nothing to shut down clears it.
+ beforeEach(() => { initPostProcessAPI({} as never); shutdownPostProcessAPI(); });
+ afterEach(() => shutdownPostProcessAPI());
+
+ it('brings back a pipeline the last App shut down', () => {
+ const engine = core(true);
+ initPostProcessAPI(engine as never);
+ shutdownPostProcessAPI();
+ expect(engine.calls).toEqual(['shutdown']);
+ initPostProcessAPI(engine as never);
+ expect(engine.calls).toEqual(['shutdown', 'init']);
+ expect(engine.postprocess_isInitialized()).toBe(true);
+ });
+
+ it('leaves a running one alone: the first boot, where the renderer started it', () => {
+ const engine = core(true);
+ initPostProcessAPI(engine as never);
+ expect(engine.calls).toEqual([]);
+ });
+
+ it('starts nothing on a first boot: the renderer starts its own, and one started early would be a second', () => {
+ const engine = core(false);
+ initPostProcessAPI(engine as never);
+ expect(engine.calls).toEqual([]);
+ });
+
+ it('asks nothing of a core built without post-processing', () => {
+ expect(() => initPostProcessAPI({} as never)).not.toThrow();
+ });
+});
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cpp
index 5b129f1be..84065a71c 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp
@@ -39,7 +39,8 @@ PostProcessPipeline::PostProcessPipeline(GfxDevice& device,
: device_(device)
, context_(context)
, resourceManager_(resourceManager)
- , graph_(&graph) {
+ , graph_(&graph)
+ , frameGraph_(&graph) {
}
PostProcessPipeline::PostProcessPipeline(GfxDevice& device,
@@ -229,7 +230,9 @@ void PostProcessPipeline::shutdown() {
}
ownedGraph_.reset();
- graph_ = nullptr;
+ // Back to the frame's, not to none: the frame outlives a shutdown and goes on running its graph,
+ // so a pipeline restarted on a graph of its own declares passes nothing executes, and presents black.
+ graph_ = frameGraph_;
screenFBO_.reset();
sceneResource_ = rg::kNoResource;
screenCaptureActive_ = false;
diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hpp
index cc1377590..c0936df71 100644
--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp
+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp
@@ -626,6 +626,8 @@ private:
/// The frame's graph when one was given; `ownedGraph_` otherwise.
rg::RenderGraph* graph_ = nullptr;
+ /// The frame's graph, kept so a shutdown can hand it back. Null with no frame.
+ rg::RenderGraph* frameGraph_ = nullptr;
Unique<rg::RenderGraph> ownedGraph_;
VertexLayoutHandle screen_quad_layout_ = VertexLayoutHandle::Invalid;
BufferHandle screen_quad_vbo_ = BufferHandle::Invalid;
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index cba3b4371..d4c88f950 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -3868,6 +3868,10 @@ export const NOTED = {
{"note":"AI agents can build 3D models in the editor from steps."},
"feat(mcp): model_write says 64 shapes count at once, and the modeling check proves sixteen do":
{"note":"A mesh can blend 64 morph targets at once, up from 8."},
+ "fix(render): a linear game looks the same on every Play, where from the second on a scene with no effects showed raw linear values":
+ {"note":"A linear game looks the same on every Play."},
+ "test(editor): a scene draws the same on every Play, with effects or without":
+ {"internal":"a check, for a fix the engine commit carries"},
"feat(render): a mesh can have 256 joints where 64 imported a rig with fingers and a face as a statue":
{"note":"A mesh can have 256 joints, up from 64."},
"feat(mcp): model_write takes 256 joints, and the modeling check poses past the old limit":