Conversation
Cancel the render loop before WASM resize to prevent accessing detached TypedArray views when buffers are reallocated. Restart render loop and flush any queued writes synchronously after resize completes. This avoids the background-tab regression from PR #114's approach of using an isResizing flag cleared via requestAnimationFrame (rAF is throttled/paused in background tabs, causing writes to queue indefinitely). Changes: - terminal.ts: Add cancelRenderLoop()/flushWriteQueue(), wrap resize() in try/catch with render loop pause/restart, add defensive writeQueue - ghostty.ts: Invalidate grapheme buffers in invalidateBuffers() alongside viewport buffers to prevent stale TypedArray access Co-authored-by: 0xBigBoss <95193764+0xBigBoss@users.noreply.github.com>
Contributor
Author
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a884a3d9aa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add early return if animationFrameId is already set, preventing multiple concurrent RAF loops when resize() is called re-entrantly from an onResize listener.
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Fixes terminal crashes (SIGSEGV) when resizing while high-output programs like
cmatrix,htop, orcat /dev/urandom | base64are running.Problem
When the terminal is resized, WASM reallocates internal buffers (screen cells, viewport, grapheme data). Any
TypedArrayviews pointing at the oldArrayBufferbecome detached. If the render loop fires or awrite()hits WASM mid-resize, the terminal crashes.Solution
invalidateBuffers()alongside viewport buffers — the existing method missed theseThis avoids the background-tab regression identified in #114, where using an
isResizingflag cleared viarequestAnimationFramewould cause writes to queue indefinitely in background/hidden tabs (browsers throttle or pause rAF), leading to terminal hangs and unbounded memory growth.Changes
lib/terminal.ts: AddcancelRenderLoop()/flushWriteQueue(), wrapresize()in try/catch with render loop pause/restartlib/ghostty.ts: Free and null grapheme buffer pointers ininvalidateBuffers()Inspired by the approach in #114.
Co-authored-by: 0xBigBoss