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(ecs): scope native mutations to world ownership
yhhd3a9004ebea6
diff --git a/sdk/src/ecs/ComponentMutationReader.ts b/sdk/src/ecs/ComponentMutationReader.tsindex 66c3cb6a9..dbe64390c 100644--- a/sdk/src/ecs/ComponentMutationReader.ts+++ b/sdk/src/ecs/ComponentMutationReader.ts@@ -149,7 +149,7 @@ export class ComponentMutationReader {const pending = [...roots], visited = new Set<Entity>();while (pending.length) {const entity = pending.pop()!;- if (visited.has(entity) || !world.valid(entity)) continue;+ if (visited.has(entity) || !world.valid(entity) && !registry.valid(entity)) continue;visited.add(entity); entities.add(entity);if (hasChildren?.(entity)) for (const child of world.get(entity, Children).entities) pending.push(child);}diff --git a/sdk/src/ecs/world.ts b/sdk/src/ecs/world.tsindex 344eddc82..4ed7126ce 100644--- a/sdk/src/ecs/world.ts+++ b/sdk/src/ecs/world.ts@@ -231,7 +231,7 @@ export class World {/** @internal Refresh membership mirrors after an observed native mutation. */refreshBuiltinMembership(entity: Entity, component: AnyComponentDef): void {- if (!isBuiltinComponent(component)) return;+ if (!isBuiltinComponent(component) || !this.valid(entity)) return;const set = this.builtin_.getEntitySet(component._cppName);const present = this.builtin_.getBuiltinMethods(component._cppName).has(entity);if (set && set.has(entity) !== present) {diff --git a/sdk/tests/physics-mutation-reconcile-wasm.test.ts b/sdk/tests/physics-mutation-reconcile-wasm.test.tsindex e4d66eae6..058904f34 100644--- a/sdk/tests/physics-mutation-reconcile-wasm.test.ts+++ b/sdk/tests/physics-mutation-reconcile-wasm.test.ts@@ -237,4 +237,17 @@ describe.skipIf(!HAS_WASM || !hasSideModule('physics'))('component-driven physicexpect(world.has(bodies[0], RigidBody2D)).toBe(false);expect(hit()).toBeUndefined();});++ it('follows a native ancestor without adding it to World-owned component queries', async () => {+ const { app, world, registry, root, bodies, hit } = await scene();+ const nativeParent = registry.create();+ registry.addTransform(nativeParent, registry.getTransform(root));+ registry.setParent(bodies[0], nativeParent); await app.tick(1 / 60);+ expect(world.valid(nativeParent)).toBe(false);+ expect(world.getEntitiesWithComponents([Transform])).not.toContain(nativeParent);+ registry.setEntityEnabled!(nativeParent, false); await app.tick(1 / 60);+ expect(hit()).toBeUndefined();+ registry.setEntityEnabled!(nativeParent, true); await app.tick(1 / 60);+ expect(hit()).toBeCloseTo(-5, 3);+ });});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 9df5b9d68..77452a0e1 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(ecs): scope native mutations to world ownership':+ { note: 'Physics reconciliation follows component mutation cursors.' },'perf(physics): reuse mutation checkpoints after pause':{ note: 'Physics reconciliation follows component mutation cursors.' },'fix(ecs): invalidate projections when the core changes':