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(inspector): clear destroyed runtime entity selections
yhh1d81ac12a34a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1f56aa739..526f8a262 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,10 @@ published separately; it ships inside the editor.## [Unreleased]+### Fixed++- **Runtime inspectors clear destroyed entity selections.** A selected entity that despawns now returns no detail row instead of an empty ghost entity, including when its native slot is reused. Requests without a live selection or tree avoid traversing the world; disabled live entities remain inspectable.+## [0.79.0] - 2026-10-14### Addeddiff --git a/sdk/src/runtime/worldSnapshot.ts b/sdk/src/runtime/worldSnapshot.tsindex 0ac4cd14c..fed204533 100644--- a/sdk/src/runtime/worldSnapshot.ts+++ b/sdk/src/runtime/worldSnapshot.ts@@ -91,6 +91,8 @@ export function worldSnapshot(app: App, selectedId: number | null, withTree: boolean, opts: WorldSnapshotOptions = {},): WorldSnapshot {const world = app.world;+ if (selectedId != null && !world.valid(selectedId as never)) selectedId = null;+ if (!withTree && selectedId == null) return { tree: null, selected: null };const nameDef = getComponent('Name');const parentDef = getComponent('Parent');const ownerDef = getComponent('SceneOwner');diff --git a/sdk/tests/world-snapshot-visibility-wasm.test.ts b/sdk/tests/world-snapshot-visibility-wasm.test.tsindex 3e896b5ae..e8e941648 100644--- a/sdk/tests/world-snapshot-visibility-wasm.test.ts+++ b/sdk/tests/world-snapshot-visibility-wasm.test.ts@@ -1,6 +1,7 @@import { beforeAll, describe, expect, it } from 'vitest';import type { App } from '../src/app/app';import type { ESEngineModule } from '../src/wasm';+import { entityIndex } from '../src/types';import { World } from '../src/ecs/world';import { Sprite, Transform, ensureBuiltinComponentsRegistered } from '../src/ecs/component';import { UINode, UIDisplay } from '../src/ui/core/ui-node';@@ -10,6 +11,27 @@ import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';describe.skipIf(!HAS_WASM)('snapshot visibility with borrowed core values', () => {let module: ESEngineModule;beforeAll(async () => { ensureBuiltinComponentsRegistered(); module = await loadWasmModule(); });+ it('does not substitute a recycled native entity for a destroyed selection', () => {+ const registry = new module.Registry(), world = new World();+ world.connectCpp(registry, module);+ const app = { world, hasResource: () => false } as unknown as App;+ try {+ const old = world.spawn('Old selection');+ world.insert(old, Sprite, { enabled: false });+ expect(worldSnapshot(app, old, false).selected?.name).toBe('Old selection');+ world.despawn(old);+ const replacement = world.spawn('Replacement');+ world.insert(replacement, Sprite, { enabled: true });+ expect(replacement).not.toBe(old);+ expect(entityIndex(replacement)).toBe(entityIndex(old));+ expect(worldSnapshot(app, old, false).selected).toBeNull();+ const snapshot = worldSnapshot(app, old, true);+ expect(snapshot.selected).toBeNull();+ expect(snapshot.tree!.entities.map(e => e.id)).toEqual([replacement]);+ expect(worldSnapshot(app, replacement, false).selected).toMatchObject({ name: 'Replacement', hidden: false });+ } finally { world.disconnectCpp(); registry.delete(); }+ });+it('keeps opposite flags and selected values independent across snapshots', () => {const registry = new module.Registry(), world = new World();world.connectCpp(registry, module);diff --git a/sdk/tests/world-snapshot-visibility.test.ts b/sdk/tests/world-snapshot-visibility.test.tsindex bfc49ff2a..a41f0a87a 100644--- a/sdk/tests/world-snapshot-visibility.test.ts+++ b/sdk/tests/world-snapshot-visibility.test.ts@@ -1,7 +1,7 @@-import { describe, it, expect } from 'vitest';+import { describe, it, expect, vi } from 'vitest';import type { App } from '../src/app/app';import { World } from '../src/ecs/world';-import { Sprite, Transform, defineComponent, unregisterComponent, ensureBuiltinComponentsRegistered } from '../src/ecs/component';+import { Sprite, Transform, Disabled, defineComponent, unregisterComponent, ensureBuiltinComponentsRegistered } from '../src/ecs/component';import { UINode, UIDisplay } from '../src/ui/core/ui-node';import { hasVisibility, isEntityVisible } from '../src/ecs/entityUtils';import { worldSnapshot } from '../src/runtime/worldSnapshot';@@ -15,6 +15,23 @@ function fixture() {}describe('runtime snapshot visibility', () => {+ it('clears destroyed selections while keeping the remaining tree and disabled entities', () => {+ const { world, app } = fixture();+ const removed = world.spawn('Removed'), remaining = world.spawn('Remaining');+ world.insert(remaining, Sprite, { enabled: false });+ world.insert(remaining, Disabled);+ expect(worldSnapshot(app, removed, false).selected?.name).toBe('Removed');+ world.despawn(removed);+ const snapshot = worldSnapshot(app, removed, true);+ expect(snapshot.selected).toBeNull();+ expect(snapshot.tree!.entities.map(e => e.id)).toEqual([remaining]);+ expect(worldSnapshot(app, remaining, false).selected?.name).toBe('Remaining');+ const enumerate = vi.spyOn(world, 'getAllEntities');+ expect(worldSnapshot(app, removed, false)).toEqual({ tree: null, selected: null });+ expect(worldSnapshot(app, null, false)).toEqual({ tree: null, selected: null });+ expect(enumerate).not.toHaveBeenCalled();+ });+it('matches UI priority, sprite flags and bare entity semantics without repeated has checks', () => {const { world, app } = fixture();const shown = world.spawn('Shown'), hidden = world.spawn('Hidden'), ui = world.spawn('UI'), bare = world.spawn('Bare');diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 5861b9234..de68e8cd5 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(inspector): clear destroyed runtime entity selections':+ { note: 'Runtime inspectors clear destroyed entity selections.' },'perf(inspector): reuse membership and readers for snapshot visibility':{ note: 'Runtime snapshots reuse visibility membership and direct readers.' },'perf(ecs): batch builtin component inspection through the core':