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): release text input measurement atlases on exit

yhhd964dc0273d2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33b738b56..03012d421 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@ published separately; it ships inside the editor.
## [Unreleased]
+### Fixed
+
+- **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-14
### Fixed
diff --git a/sdk/src/ui/text/text-input-plugin.ts b/sdk/src/ui/text/text-input-plugin.ts
index 3060f72c0..0aa916e08 100644
--- a/sdk/src/ui/text/text-input-plugin.ts
+++ b/sdk/src/ui/text/text-input-plugin.ts
@@ -177,6 +177,9 @@ export class TextInputPlugin implements Plugin {
if (world.valid(ch.caret)) world.despawn(ch.caret);
}
childrenOf.clear();
+ const renderer = measureRenderer;
+ measureRenderer = null;
+ renderer?.dispose();
});
function syncFromEditor(): void {
diff --git a/sdk/tests/text-input-plugin-lifecycle.test.ts b/sdk/tests/text-input-plugin-lifecycle.test.ts
index d755d6690..c1ce4d0f6 100644
--- a/sdk/tests/text-input-plugin-lifecycle.test.ts
+++ b/sdk/tests/text-input-plugin-lifecycle.test.ts
@@ -4,6 +4,21 @@ import { afterEach, expect, it, vi } from 'vitest';
import type { TextEditorEvent } from '../src/platform/types';
import { bootMockApp } from './helpers/mockApp';
+const measurements = vi.hoisted(() => [] as Array<{ dispose: ReturnType<typeof vi.fn> }>);
+const dimensions = vi.hoisted(() => ({ width: vi.fn(() => 0), height: vi.fn(() => 0) }));
+vi.mock('../src/ui/util/helpers', async original => ({
+ ...await original<typeof import('../src/ui/util/helpers')>(),
+ getUINodeWidth: dimensions.width,
+ getUINodeHeight: dimensions.height,
+}));
+vi.mock('../src/ui/text/text-renderer', () => ({
+ SdfTextRenderer: class {
+ atlas = { renderSize: 64, getGlyph: () => ({ advance: 16 }) };
+ dispose = vi.fn();
+ constructor() { measurements.push(this); }
+ },
+}));
+
const surfaces: ReturnType<typeof createSurface>[] = [];
function createSurface() {
const listeners = new Set<(event: TextEditorEvent) => void>();
@@ -32,7 +47,8 @@ const { FocusManager, FocusManagerState } = await import('../src/ui/input/focusa
const { UIEvents, UIEventQueue } = await import('../src/ui/core/events');
const { TextInput } = await import('../src/ui/text/text-input');
const { defineSystem, Schedule } = await import('../src/ecs/system');
-const { Disabled } = await import('../src/ecs/component');
+const { Disabled, Transform } = await import('../src/ecs/component');
+const { UINode } = await import('../src/ui/core/ui-node');
const { Interactable } = await import('../src/ui/input/interactable');
const apps: ReturnType<typeof App.new>[] = [];
function build(plugin: InstanceType<typeof TextInputPlugin>) {
@@ -47,6 +63,9 @@ function build(plugin: InstanceType<typeof TextInputPlugin>) {
afterEach(() => {
for (const app of apps.splice(0)) app.quit();
surfaces.length = 0;
+ measurements.length = 0;
+ dimensions.width.mockReturnValue(0);
+ dimensions.height.mockReturnValue(0);
});
it.each(['change', 'composition', 'submit'] as const)('delivers native %s after UI clearing and before Update consumers', async kind => {
@@ -184,3 +203,25 @@ it.each(['entity', 'ancestor', 'interaction'] as const)('rejects queued input af
expect(surfaces[0].blur).toHaveBeenCalledOnce();
expect(app.world.get(field, TextInput).focused).toBe(false);
});
+
+it('releases each App measurement atlas without disposing the newer field atlas', async () => {
+ dimensions.width.mockReturnValue(160);
+ dimensions.height.mockReturnValue(40);
+ const plugin = new TextInputPlugin();
+ const prepare = async () => {
+ const app = build(plugin), field = app.world.spawn();
+ app.world.insert(field, Transform, {});
+ app.world.insert(field, UINode, {});
+ app.world.insert(field, TextInput, { value: 'preview' });
+ await app.tick(1 / 60);
+ return app;
+ };
+ const first = await prepare(), second = await prepare();
+ expect(measurements).toHaveLength(2);
+ first.quit();
+ expect(measurements[0].dispose).toHaveBeenCalledOnce();
+ expect(measurements[1].dispose).not.toHaveBeenCalled();
+ second.quit();
+ second.quit();
+ expect(measurements[1].dispose).toHaveBeenCalledOnce();
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index c2a6dd364..bcac40649 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): 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':
{ internal: 'classifies release evidence scope without changing shipped runtime behavior' },
'fix(text): isolate App glyph caches and release owned pages':