Repository navigation
fix: solve #4010 — clear WebGL texture atlas on terminal reattach/resize - #4011
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Expose `clearTextureAtlas()` from the xterm WebGL addon via `createTerminalInWrapper` and call it before `xterm.refresh()` in `fitAndRefresh` whenever the cached terminal is reattached to a container, or whenever a resize changes the terminal dimensions. The macOS GPU compositor can drop or corrupt atlas pages without firing `onContextLoss`, leaving stale glyph textures that paint as RTL-looking gibberish across an otherwise readable terminal. Forcing the atlas to rebuild on every reattach removes the stale state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
onContextLoss.xterm.refresh()then paints from the corrupt atlas, producing the RTL-looking glyphs reported in [bug] Terminal intermittently renders English text as RTL-looking gibberish #4010.clearTextureAtlas()fromWebglAddonviacreateTerminalInWrapperand call it insidefitAndRefreshwhenever the cached terminal is reattached to a container (always) or a resize changes terminal dimensions. This forces the GPU renderer to rebuild glyphs on every reattach so stale/garbage texture coordinates can't leak through.v1-terminal-cache.test.tsshadow-tests the decision logic infitAndRefresh/attachToContainer— verifying atlas invalidation order (clear-before-refresh), forced clear on reattach, conditional clear on resize, and no-op on spurious ResizeObserver fires. Real WebGL/xterm aren't available under bun:test, so the tests mirror the production code paths against mocks.What changed
helpers.ts—createTerminalInWrappernow returns aclearTextureAtlascallback that safely no-ops when WebGL is unavailable (DOM fallback after context loss or addon load failure).v1-terminal-cache.ts—CachedTerminalcarries the new callback;fitAndRefreshaccepts aclearAtlasoption and invokes the callback beforexterm.refresh()when forced or when fit changed dimensions;attachToContaineralways passesclearAtlas: true.Why partial vs. full fix
Issue #4010 has no deterministic repro (intermittent during extended terminal sessions). Tab-switch / window-resize is the most common trigger and is fully covered here. Pure idle-corruption (no reattach, no resize) would need additional triggers (focus / visibility / display-wake) — out of scope for this minimal fix.
Test plan
bun test apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/— 72 tests pass (6 new)bun run lint:fix— cleancd apps/desktop && bun run typecheck— cleanCloses #4010
Summary by cubic
Clears the WebGL texture atlas on terminal reattach and on dimension-changing resize to stop corrupted glyphs on macOS. Rebuilds glyphs before refresh, resolving #4010.
clearTextureAtlas()fromWebglAddonviacreateTerminalInWrapper(no-op if WebGL is unavailable).v1-terminal-cache: callfitAndRefresh(..., { clearAtlas: true })on reattach; clear atlas only when resize changes cols/rows; always clear beforexterm.refresh().Written for commit 96fbaf0. Summary will update on new commits.