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(postprocess): re-push a camera's passes after the engine's list is cleared
esengine6c147d29eade
diff --git a/sdk/src/postprocess/PostProcessAPI.ts b/sdk/src/postprocess/PostProcessAPI.tsindex 98127d30b..f714ad696 100644--- a/sdk/src/postprocess/PostProcessAPI.ts+++ b/sdk/src/postprocess/PostProcessAPI.ts@@ -65,8 +65,14 @@ function getModule(): PostProcessCore {return module;}-export function syncStackToWasm(stack: PostProcessStack): void {- if (!stack.isDirty) return;+/**+ * Push a stack's enabled passes to the engine. `force` re-pushes a stack that has+ * not been edited — needed because the engine's pass list is torn down after every+ * camera (see {@link PostProcessAPI._resetAfterCamera}), so "not dirty" says the+ * stack is unchanged, NOT that the engine still holds it.+ */+export function syncStackToWasm(stack: PostProcessStack, force = false): void {+ if (!force && !stack.isDirty) return;const m = getModule();@@ -129,6 +135,14 @@ export class PostProcessAPI {readonly volumeStacks = new Map<Entity, PostProcessStack>();readonly volumeShaders = new Map<string, ShaderHandle>();+ /**+ * Which stack the engine's pass list currently holds, or null when it holds+ * none. Distinct from the stack's own dirty flag, which only tracks edits:+ * every camera ends by clearing the engine's passes, so a stack that was+ * pushed last frame and never edited must still be pushed again this frame.+ */+ private engineStack_: PostProcessStack | null = null;+// -- per-App state (stacks / bindings / screen stack) --------------------get screenStack(): PostProcessStack | null {@@ -241,13 +255,15 @@ export class PostProcessAPI {}this.setBypass(false);- syncStackToWasm(stack);+ syncStackToWasm(stack, /*force=*/this.engineStack_ !== stack);+ this.engineStack_ = stack;}_resetAfterCamera(): void {try {getModule().postprocess_clearPasses();getModule().postprocess_setBypass(true);+ this.engineStack_ = null;} catch (e) {handleWasmError(e, 'PostProcess._resetAfterCamera');}diff --git a/sdk/tests/postprocess.test.ts b/sdk/tests/postprocess.test.tsindex e9e08bca2..e90dc6327 100644--- a/sdk/tests/postprocess.test.ts+++ b/sdk/tests/postprocess.test.ts@@ -309,6 +309,34 @@ describe('PostProcess API', () => {pp._applyForCamera(1 as any);expect(mock.postprocess_setUniformVec4).toHaveBeenCalledWith('bloom', 'u_color', 1, 0.5, 0.25, 1);});++ // Every camera ends by clearing the engine's pass list, so an unedited+ // stack still has to be re-pushed the next frame. Trusting the stack's+ // dirty flag alone left the engine with zero passes from frame 2 on.+ it('re-pushes an unedited stack after the engine\'s passes were reset', () => {+ const stack = pp.createStack();+ stack.addPass('bloom', 42);+ pp.bind(1 as any, stack);++ pp._applyForCamera(1 as any);+ pp._resetAfterCamera();+ mock.postprocess_addPass.mockClear();++ pp._applyForCamera(1 as any);+ expect(mock.postprocess_addPass).toHaveBeenCalledWith('bloom', 42);+ });++ it('does not re-push an unedited stack the engine still holds', () => {+ const stack = pp.createStack();+ stack.addPass('bloom', 42);+ pp.bind(1 as any, stack);++ pp._applyForCamera(1 as any);+ mock.postprocess_addPass.mockClear();++ pp._applyForCamera(1 as any);+ expect(mock.postprocess_addPass).not.toHaveBeenCalled();+ });});// =========================================================================