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(editor): undo of an omitted Transform field no longer crashes wasm
esenginefa9d80b87ed7
diff --git a/desktop/src/engine/Reconciler.ts b/desktop/src/engine/Reconciler.tsindex 548ff3aaa..c971d2d68 100644--- a/desktop/src/engine/Reconciler.ts+++ b/desktop/src/engine/Reconciler.ts@@ -258,7 +258,10 @@ export class ReconcilerImpl {const defaults = componentDefaults(def);const out: Record<string, unknown> = {};for (const key of Object.keys(defaults)) {- out[key] = key in data ? this.resolveRefs(data[key]) : defaults[key];+ // A field that is absent OR explicitly undefined (e.g. undo restoring a+ // partial component's untouched field) falls back to the default — the wasm+ // bindings reject an undefined POD field (`'w' in undefined`).+ out[key] = data[key] !== undefined ? this.resolveRefs(data[key]) : defaults[key];}return out;}diff --git a/desktop/tests/engine-model-sync.test.ts b/desktop/tests/engine-model-sync.test.tsindex bf59dec50..5772f9888 100644--- a/desktop/tests/engine-model-sync.test.ts+++ b/desktop/tests/engine-model-sync.test.ts@@ -104,6 +104,17 @@ describe.skipIf(!HAS_WASM)('Model-authoritative projection + lossless save', ()expect(t.position.x).toBe(0);});+ it('undo of an edit to a field the Transform omitted restores the default, not undefined (was a wasm crash)', () => {+ // Authored scenes routinely omit rotation (it defaults to identity). Editing it+ // records before=undefined, so undo used to project rotation:undefined → the+ // wasm bindings threw "Cannot use 'in' operator to search for 'w' in undefined".+ const src = S.model.addEntity('Partial', [{ type: 'Transform', data: { position: { x: 1, y: 2, z: 0 } } }] as never);+ const rt = S.model.runtimeFor(src)!;+ S.commands.setField(src, 'Transform', 'rotation', 'angle', 45);+ expect(() => S.history.undo()).not.toThrow();+ expect((host.world.get(rt, Transform).rotation as { w: number }).w).toBe(1); // identity, not undefined+ });+it('addEntity / undo is reflected in the model', () => {const before = S.model.serialize()!.entities.length;S.commands.addEntity();