wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.83k stars 799 forks source link

Crash on MacOS #2262

Closed abusch closed 2 years ago

abusch commented 2 years ago

What Operating System(s) are you seeing this problem on?

macOS

WezTerm version

20220624-141144-bd1b7c5d

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

No, and I'll explain why below

Describe the bug

wezterm-gui crashed when closing a pane.

To Reproduce

I had a tab with neovim running. I opened a vertical split, then closed it, and wezterm crashed. I had a couple of other tabs open in that session as well, but no other window or workspace.

Configuration

local wezterm = require 'wezterm';
local act = wezterm.action

local function ends_with(str, ending)
   return ending == "" or str:sub(-#ending) == ending
end

-- local function activate_pane(direction)
--   return function(win, pane)
--       local proc_name = pane:get_foreground_process_name()
--       if ends_with(proc_name, "nvim") then
--         wezterm.log_info("it's neovim!")
--         win.action(act.SendKey { key=
--       else
--         win.action(act.ActivatePaneDirection(direction), pane)
--       end
-- 
--   end
-- end

local mykeys = {
  { key = "Enter", mods = "ALT", action = act.SplitHorizontal },
  -- Pane movements
  { key = "h", mods = "ALT",
    action = act.ActivatePaneDirection("Left") },
  { key = "l", mods = "ALT",
    action = act.ActivatePaneDirection("Right") },
  { key = "k", mods = "ALT",
    action = act.ActivatePaneDirection("Up") },
  { key = "j", mods = "ALT",
    action = act.ActivatePaneDirection("Down") },
  -- Tab movements
  { key = "h", mods = "CMD",
    action = act.ActivateTabRelative(-1) },
  { key = "l", mods = "CMD",
    action = act.ActivateTabRelative(1) },
  { key = "n", mods = "CMD",
    action = act.SpawnTab("CurrentPaneDomain") },
--  { key = "f", mods = "ALT", action = wezterm.action_callback(function(win, pane)
--      local proc_name = pane:get_foreground_process_name()
--      if ends_with(proc_name, "nvim") then
--        wezterm.log_info("it's neovim!")
--      end
--   end) },
}

for i = 1, 8 do
  -- ALT + number to activate that tab
  table.insert(mykeys, {
    key = tostring(i),
    mods = "ALT",
    action = act.ActivateTab(i - 1),
  })
end

wezterm.on("update-right-status", function(window, pane)
  -- Each element holds the text for a cell in a "powerline" style << fade
  local cells = {};

  -- Figure out the cwd and host of the current pane.
  -- This will pick up the hostname for the remote host if your
  -- shell is using OSC 7 on the remote host.
  local cwd_uri = pane:get_current_working_dir()
  if cwd_uri then
    cwd_uri = cwd_uri:sub(8);
    local slash = cwd_uri:find("/")
    local cwd = ""
    local hostname = ""
    if slash then
      hostname = cwd_uri:sub(1, slash-1)
      -- Remove the domain name portion of the hostname
      local dot = hostname:find("[.]")
      if dot then
        hostname = hostname:sub(1, dot-1)
      end
      -- and extract the cwd from the uri
      cwd = cwd_uri:sub(slash)

      table.insert(cells, cwd);
      table.insert(cells, hostname);
    end
  end

  -- I like my date/time in this style: "Wed Mar 3 08:14"
  local date = wezterm.strftime("%a %b %-d %H:%M");
  table.insert(cells, date);

  -- An entry for each battery (typically 0 or 1 battery)
  for _, b in ipairs(wezterm.battery_info()) do
    table.insert(cells, string.format("%.0f%%", b.state_of_charge * 100))
  end

  -- The powerline < symbol
  local LEFT_ARROW = utf8.char(0xe0b3);
  -- The filled in variant of the < symbol
  local SOLID_LEFT_ARROW = utf8.char(0xe0b2)

  -- Color palette for the backgrounds of each cell
  local colors = {
    "#3c1361",
    "#52307c",
    "#663a82",
    "#7c5295",
    "#b491c8",
  };

  -- Foreground color for the text across the fade
  local text_fg = "#c0c0c0";

  -- The elements to be formatted
  local elements = {};
  -- How many cells have been formatted
  local num_cells = 0;

  -- Translate a cell into elements
  local function push(text, is_last)
    local cell_no = num_cells + 1
    table.insert(elements, {Foreground={Color=text_fg}})
    table.insert(elements, {Background={Color=colors[cell_no]}})
    table.insert(elements, {Text=" "..text.." "})
    if not is_last then
      table.insert(elements, {Foreground={Color=colors[cell_no+1]}})
      table.insert(elements, {Text=SOLID_LEFT_ARROW})
    end
    num_cells = num_cells + 1
  end

  while #cells > 0 do
    local cell = table.remove(cells, 1)
    push(cell, #cells == 0)
  end

  window:set_right_status(wezterm.format(elements));
end);

return {
  use_fancy_tab_bar = false,
  tab_bar_at_bottom = true,
  color_scheme = "Dracula",
  harfbuzz_features = { "clig=1" },
  font = wezterm.font("JetBrains Mono"),
  font_size = 13,

  keys = mykeys
}

Expected Behavior

No response

Logs

14:00:32.918  ERROR  env_bootstrap                   > panic at term/src/screen.rs:430:9 - !?
   0: backtrace::backtrace::trace
   1: backtrace::capture::Backtrace::new
   2: env_bootstrap::register_panic_hook::{{closure}}
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic_handler::{{closure}}
   5: std::sys_common::backtrace::__rust_end_short_backtrace
   6: _rust_begin_unwind
   7: core::panicking::panic_fmt
   8: wezterm_term::screen::Screen::resize
   9: wezterm_term::terminalstate::TerminalState::resize
  10: <mux::localpane::LocalPane as mux::pane::Pane>::resize
  11: mux::tab::Tab::prune_dead_panes
  12: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  13: mux::window::Window::prune_dead_tabs
  14: mux::Mux::prune_dead_windows
  15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
  16: async_task::raw::RawTask<F,T,S>::run
  17: window::spawn::SpawnQueue::run
  18: window::spawn::SpawnQueue::trigger
  19: <unknown>
  20: <unknown>
  21: <unknown>
  22: <unknown>
  23: <unknown>
  24: <unknown>
  25: <unknown>
  26: <unknown>
  27: <unknown>
  28: <unknown>
  29: <window::os::macos::connection::Connection as window::connection::ConnectionOps>::run_message_loop
  30: wezterm_gui::main
  31: std::sys_common::backtrace::__rust_begin_short_backtrace
  32: std::rt::lang_start::{{closure}}
  33: std::rt::lang_start_internal
  34: _main

14:00:32.943  ERROR  env_bootstrap                   > panic at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/thread/local.rs:418:26 - !?
   0: backtrace::backtrace::trace
   1: backtrace::capture::Backtrace::new
   2: env_bootstrap::register_panic_hook::{{closure}}
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic_handler::{{closure}}
   5: std::sys_common::backtrace::__rust_end_short_backtrace
   6: _rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: std::thread::local::LocalKey<T>::with
  10: core::ptr::drop_in_place<wezterm_gui::frontend::GuiFrontEnd>
  11: std::thread::local::fast::destroy_value
  12: std::sys::unix::thread_local_dtor::register_dtor::run_dtors

Anything else?

No response

wez commented 2 years ago

Can you try a nightly build? https://wezfurlong.org/wezterm/install/macos.html#installing-on-macos

abusch commented 2 years ago

Sure, I've switched to the nightly builds and see if it happens again.

abusch commented 2 years ago

From what I can tell from the backtrace, it seems to happen on this line: https://github.com/wez/wezterm/blob/main/term/src/screen.rs#L197 where Screen::phys_row() is called with a negative row (i.e cursor.y would be negative), triggering the assert. I am not familiar enough with the code to know why that would be the case though 😅

wez commented 2 years ago

It doesn't reproduce for me, but I suspect that it is related to rewrapping lines leaving the cursor position in slightly the wrong place.

Possibly the same root cause as either or both of:

Can you try to figure out what output in the pane(s) causes this to happen? I'm assuming that a specific number and width of lines is necessary. With that, it will be much easier to figure out how to resolve this!

github-actions[bot] commented 2 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.