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(ui): scope screen-domain lookup to its registry

yhh6e8ff0cafccb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48a0dafc0..4b75c2e2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Screen-domain queries reject another world's cached entities.** The UI binding checks registry identity and entity validity before using the resolved screen-domain cache, preventing reused IDs from borrowing a previous world's pointer coordinates and excluding despawned nodes before the next layout pass.
+
- **Authored UI hiding cancels dragging before another layout pass.** Hiding a dragged node or its ancestor stops capture and emits one drag-end event immediately on the next sample, including visibility changes inside drag callbacks. Stale hover cannot start a hidden control, and showing it again does not resume an old capture. Dragging and keyboard focus share the same live visibility rules.
- **Dense change queries bind their live sequence index once.** Added and Changed filters reuse component-specific matchers during entity iteration, avoiding repeated world and component lookups while retaining precise system boundaries, stable-frame skipping and visibility of later component replacements.
diff --git a/sdk/tests/ui-screen-domain-worlds-wasm.test.ts b/sdk/tests/ui-screen-domain-worlds-wasm.test.ts
new file mode 100644
index 000000000..d8e2a101c
--- /dev/null
+++ b/sdk/tests/ui-screen-domain-worlds-wasm.test.ts
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { afterEach, beforeAll, describe, expect, it } from 'vitest';
+import { App } from '../src/app/app';
+import { AppContext, setDefaultContext } from '../src/ecs/context';
+import { Canvas, Transform } from '../src/ecs/component';
+import { UINode } from '../src/ui/core/ui-node';
+import type { CppRegistry, ESEngineModule } from '../src/wasm';
+import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';
+
+describe.skipIf(!HAS_WASM)('screen domain ownership on real WASM', () => {
+ let engine: ESEngineModule;
+ const worlds: Array<{ app: App; registry: CppRegistry }> = [];
+ beforeAll(async () => { engine = await loadWasmModule(); });
+ afterEach(() => {
+ for (const { app, registry } of worlds.splice(0)) {
+ for (const entity of app.world.getAllEntities()) app.world.despawn(entity);
+ app.world.disconnectCpp();
+ registry.delete();
+ }
+ });
+ const make = (screen: boolean) => {
+ setDefaultContext(new AppContext());
+ const registry = new engine.Registry(), app = App.new();
+ app.connectCpp(registry, engine);
+ worlds.push({ app, registry });
+ const entity = app.world.spawn();
+ app.world.insert(entity, Transform);
+ app.world.insert(entity, UINode);
+ if (screen) app.world.insert(entity, Canvas);
+ return { app, registry, entity };
+ };
+ it('does not borrow a screen-domain entry from another registry with the same entity ID', () => {
+ const first = make(true);
+ engine.uiLayout_update(first.registry, -50, -50, 50, 50, true);
+ expect(engine.ui_isScreenDomain!(first.registry, first.entity)).toBe(true);
+ const second = make(false);
+ expect(second.entity).toBe(first.entity);
+ expect(engine.ui_isScreenDomain!(second.registry, second.entity)).toBe(false);
+ expect(engine.ui_isScreenDomain!(first.registry, first.entity)).toBe(true);
+ engine.uiLayout_update(second.registry, -50, -50, 50, 50, true);
+ expect(engine.ui_isScreenDomain!(second.registry, second.entity)).toBe(false);
+ engine.uiLayout_update(first.registry, -50, -50, 50, 50, true);
+ expect(engine.ui_isScreenDomain!(first.registry, first.entity)).toBe(true);
+ });
+ it('does not classify a despawned entity using the previous layout entry', () => {
+ const { app, registry, entity } = make(true);
+ engine.uiLayout_update(registry, -50, -50, 50, 50, true);
+ expect(engine.ui_isScreenDomain!(registry, entity)).toBe(true);
+ app.world.despawn(entity);
+ expect(engine.ui_isScreenDomain!(registry, entity)).toBe(false);
+ });
+});
diff --git a/src/esengine/bindings/UIBindings.cpp b/src/esengine/bindings/UIBindings.cpp
index e4dde1924..a23318bf8 100644
--- a/src/esengine/bindings/UIBindings.cpp
+++ b/src/esengine/bindings/UIBindings.cpp
@@ -104,9 +104,8 @@ u32 ui_getCullBit(ecs::Registry& registry, u32 entity) {
}
bool ui_isScreenDomain(ecs::Registry& registry, u32 entity) {
- (void)registry;
auto* ui = ctx().tryGet<ecs::UISystem>();
- return ui && ui->screenDomain().count(entity) != 0;
+ return ui && ui->isScreenDomain(registry, entity);
}
// UINode (CSS box) computed size — its internal computed_size_ is not
diff --git a/src/esengine/ui/UISystem.hpp b/src/esengine/ui/UISystem.hpp
index 6d30357d4..26fd755d2 100644
--- a/src/esengine/ui/UISystem.hpp
+++ b/src/esengine/ui/UISystem.hpp
@@ -132,6 +132,13 @@ public:
*/
const std::unordered_set<u32>& screenDomain() const { return screen_domain_; }
+ bool isScreenDomain(const Registry& registry, u32 entity) const {
+ // Resolved entries belong to the registry that last completed layout.
+ return lastRegistryId_ == registry.instanceId()
+ && registry.valid(Entity::fromRaw(entity))
+ && screen_domain_.count(entity) != 0;
+ }
+
private:
struct InheritedState {
bool hidden = false;
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index d6f488c25..3663e9202 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(ui): scope screen-domain lookup to its registry':
+ { note: 'Screen-domain queries reject another world\'s cached entities.' },
'fix(ui): cancel drag captures from authored visibility changes':
{ note: 'Authored UI hiding cancels dragging before another layout pass.' },
'fix(test): present golden browser packages on a shared display':