Skip to content

Conversation

@forketyfork
Copy link
Owner

Summary

Fixes a segmentation fault that occurred when entering full terminal mode (or any mode transition that triggers a terminal resize with font scale changes).

Root Cause

The VT stream handler (vt_stream::Handler) contains a ReadonlyHandler that holds pointers to the terminal's internal buffer structures. When the terminal is resized:

  1. Font scale changes from grid scale to 1.0, triggering applyTerminalResize
  2. terminal.resize() reallocates internal buffers, invalidating pointers in the ReadonlyHandler
  3. Later in the same frame, processOutput() attempts to read from the stream with stale pointers → segfault at 0x164545398

Solution

Recreate the VT stream after each terminal resize to ensure the stream handler has fresh pointers to the resized terminal's internal state.

Changes

  • Added vt_stream import to main.zig
  • Modified applyTerminalResize() to deinit and recreate the stream after terminal resize
  • Refactored the resize loop to use early continues for cleaner control flow

Test Plan

  • Build succeeds (zig build)
  • Tests pass (zig build test)
  • Manual testing: Enter full terminal mode without crashes

When the terminal is resized (e.g., when switching from grid mode to full mode with different font scales), the VT stream handler contained stale pointers to the terminal's internal buffer structures. After terminal.resize() reallocates buffers, the ReadonlyHandler in the stream had invalid pointers, causing a segfault when processOutput() attempted to read from the stream.

Solution: Recreate the VT stream after each terminal resize to ensure the stream handler has fresh pointers to the resized terminal's internal state.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6c8072414

ℹ️ 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".

@forketyfork forketyfork requested a review from Copilot January 12, 2026 07:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a segmentation fault that occurred when switching to full terminal mode by addressing stale pointers in the VT stream handler after terminal resizing.

Changes:

  • Added stream recreation logic after terminal resize to maintain valid pointers
  • Refactored resize loop to use early continues for improved control flow
  • Added vt_stream import to support stream recreation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@forketyfork forketyfork merged commit db65793 into main Jan 12, 2026
5 checks passed
@forketyfork forketyfork deleted the fix/stream-invalidation-on-resize branch January 12, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants