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(ui): scope inline text cleanup and release measurement pages
yhhc27393dc7610
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 03012d421..df2a90d68 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Inline rich text releases its own measurement atlas.** Cleanup belongs to each App, so closing an older preview cannot remove a newer preview's inline image children. Exiting releases measurement glyph pages and repeated cleanup remains safe.+- **Input fields release their measurement glyph pages on exit.** App teardown disposes the caret measurement atlas as well as the visible text atlas, preventing a 4 MiB page from accumulating on each preview restart. Cleanup stays scoped to the exiting App.## [0.83.0] - 2026-10-14diff --git a/sdk/src/ui/text/inline-image-plugin.ts b/sdk/src/ui/text/inline-image-plugin.tsindex 548995cdc..35bc510c7 100644--- a/sdk/src/ui/text/inline-image-plugin.ts+++ b/sdk/src/ui/text/inline-image-plugin.ts@@ -40,14 +40,26 @@ export class InlineImagePlugin implements Plugin {name = 'ui-inline-image';readonly profileDomain = 'ui';- private cleanup_: (() => void) | null = null;-- cleanup(): void {- this.cleanup_?.();- this.cleanup_ = null;+ private readonly cleanups_ = new Map<App, () => void>();++ cleanup(app?: App): void {+ if (app) {+ const cleanup = this.cleanups_.get(app);+ this.cleanups_.delete(app);+ cleanup?.();+ } else {+ const cleanups = [...this.cleanups_.values()];+ this.cleanups_.clear();+ const errors: unknown[] = [];+ for (const cleanup of cleanups) {+ try { cleanup(); } catch (error) { errors.push(error); }+ }+ if (errors.length) throw new Error(`Failed to release inline image resources: ${errors.map(String).join('; ')}`);+ }}build(app: App): void {+ this.cleanup(app);if (!app.pipeline) return; // logic-only host → nothing to draw// Null on the native core, which rasterizes glyphs through the platform// instead of the wasm heap — the measurement atlas below takes either.@@ -191,10 +203,16 @@ export class InlineImagePlugin implements Plugin {}}- this.cleanup_ = () => {- for (const kids of childrenOf.values()) despawnKids(kids);- childrenOf.clear();- };+ this.cleanups_.set(app, () => {+ try {+ for (const kids of childrenOf.values()) despawnKids(kids);+ } finally {+ childrenOf.clear();+ const renderer = measurer;+ measurer = null;+ renderer?.dispose();+ }+ });}}diff --git a/sdk/tests/inline-image-plugin-lifecycle.test.ts b/sdk/tests/inline-image-plugin-lifecycle.test.tsnew file mode 100644index 000000000..140fcc2b0--- /dev/null+++ b/sdk/tests/inline-image-plugin-lifecycle.test.ts@@ -0,0 +1,60 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { afterEach, expect, it, vi } from 'vitest';+import { bootMockApp } from './helpers/mockApp';+import { RenderPipeline } from '../src/render/renderPipeline';+import { Transform } from '../src/ecs/component';+import { UINode } from '../src/ui/core/ui-node';+import { Text } from '../src/ui/core/text';+import { InlineImagePlugin } from '../src/ui/text/inline-image-plugin';++const renderers = vi.hoisted(() => [] as Array<{ dispose: ReturnType<typeof vi.fn> }>);+vi.mock('../src/ui/util/helpers', async original => ({+ ...await original<typeof import('../src/ui/util/helpers')>(),+ getUINodeWidth: () => 320,+ getUINodeHeight: () => 48,+}));+vi.mock('../src/ui/text/text-renderer', () => ({+ SdfTextRenderer: class {+ atlas = {+ pixelSizeFor: () => 64,+ getGlyph: () => ({+ pageId: 1, u0: 0, v0: 0, u1: 1, v1: 1,+ width: 16, height: 32, advance: 16, bearingX: 0, bearingY: 24,+ }),+ };+ dispose = vi.fn();+ constructor() { renderers.push(this); }+ },+}));+const apps: ReturnType<typeof bootMockApp>['app'][] = [];+afterEach(() => {+ for (const app of apps.splice(0)) app.quit();+ renderers.length = 0;+});++it('keeps inline measurement pages scoped to the App being closed', async () => {+ const plugin = new InlineImagePlugin();+ const prepare = async () => {+ const { app } = bootMockApp();+ apps.push(app);+ app.setPipeline(new RenderPipeline());+ app.addPlugin(plugin);+ const label = app.world.spawn();+ app.world.insert(label, Transform, {});+ app.world.insert(label, UINode, {});+ app.world.insert(label, Text, {+ content: 'A<img src="icon.png" width="16" height="16">Ω', richText: true,+ });+ await app.tick(1 / 60);+ return app;+ };+ const first = await prepare(), second = await prepare();+ expect(renderers).toHaveLength(2);+ first.quit();+ expect(renderers[0].dispose).toHaveBeenCalledOnce();+ expect(renderers[1].dispose).not.toHaveBeenCalled();+ second.quit();+ plugin.cleanup();+ expect(renderers[1].dispose).toHaveBeenCalledOnce();+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex bcac40649..cd9bb00e6 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 inline text cleanup and release measurement pages':+ { note: 'Inline rich text releases its own measurement atlas.' },'fix(ui): release text input measurement atlases on exit':{ note: 'Input fields release their measurement glyph pages on exit.' },'chore(release): classify 0.83 host verification coverage':