Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paged-terminal: some crashes #1600

Closed
KNnut opened this issue Mar 20, 2024 · 12 comments
Closed

paged-terminal: some crashes #1600

KNnut opened this issue Mar 20, 2024 · 12 comments

Comments

@KNnut
Copy link
Collaborator

KNnut commented Mar 20, 2024

Ghostty 0.1.0-paged-terminal+a4d3af6

Build Config

  • Zig version: 0.12.0-dev.3365+cbeab678a
  • build mode : builtin.OptimizeMode.Debug
  • app runtime: apprt.Runtime.gtk
  • font engine: font.main.Backend.fontconfig_freetype
  • renderer : renderer.OpenGL
  • libxev : main.Backend.io_uring

Crash 1

Originally posted in #1591 (comment), which still occurs to me

thread panic: attempt to use null value
src/terminal/page.zig:282:91: 0x19655e9 in cloneRowFrom (ghostty)
                const other_style = other.styles.lookupId(other.memory, src_cell.style_id).?.*;
                                                                                          ^
src/terminal/page.zig:235:74: 0x1966c69 in cloneFrom (ghostty)
        for (rows, other_rows) |*dst_row, *src_row| try self.cloneRowFrom(
                                                                         ^
src/terminal/PageList.zig:380:32: 0x1acb710 in clone (ghostty)
        try page.data.cloneFrom(
                               ^
src/terminal/Screen.zig:228:37: 0x1acdba4 in clonePool (ghostty)
    var pages = try self.pages.clone(.{
                                    ^
src/terminal/Screen.zig:210:30: 0x1acea6a in clone (ghostty)
    return try self.clonePool(alloc, null, top, bot);
                             ^
src/renderer/OpenGL.zig:693:58: 0x1afa5c3 in updateFrame (ghostty)
        var screen_copy = try state.terminal.screen.clone(
                                                         ^
src/renderer/Thread.zig:463:27: 0x1b3a628 in callback (ghostty)
    t.renderer.updateFrame(
                          ^
~/.cache/zig/p/12203116ff408eb48f81c947dfeb06f7feebf6a9efa962a560ac69463098b2c04a96/src/backend/io_uring.zig:768:29: 0x1a68ac1 in invoke (ghostty)
        return self.callback(self.userdata, loop, self, result);
                            ^
~/.cache/zig/p/12203116ff408eb48f81c947dfeb06f7feebf6a9efa962a560ac69463098b2c04a96/src/backend/io_uring.zig:159:33: 0x1a6b6c0 in tick___anon_155984 (ghostty)
                switch (c.invoke(self, cqe.res)) {
                                ^
~/.cache/zig/p/12203116ff408eb48f81c947dfeb06f7feebf6a9efa962a560ac69463098b2c04a96/src/backend/io_uring.zig:60:42: 0x1a6b85d in run (ghostty)
            .until_done => try self.tick_(.until_done),
                                         ^
src/renderer/Thread.zig:212:26: 0x1a6ba62 in threadMain_ (ghostty)
    _ = try self.loop.run(.until_done);
                         ^
src/renderer/Thread.zig:174:21: 0x1a201c5 in threadMain (ghostty)
    self.threadMain_() catch |err| {
                    ^
/usr/lib/zig/std/Thread.zig:406:13: 0x19dcfea in callFn__anon_151501 (ghostty)
            @call(.auto, f, args);
            ^
/usr/lib/zig/std/Thread.zig:674:30: 0x19818d2 in entryFn (ghostty)
                return callFn(f, args_ptr.*);
                             ^

Repro

With this init.lua

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim',
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
    {
        'catppuccin/nvim',
        name = 'catppuccin',
        priority = 1000,
        config = function()
            vim.cmd.colorscheme 'catppuccin'
        end
    },
    {
        'L3MON4D3/LuaSnip',
        config = function()
            require('luasnip.loaders.from_vscode').lazy_load()
        end,
        dependencies = {
            'rafamadriz/friendly-snippets'
        }
    },
    {
        'hrsh7th/nvim-cmp',
        dependencies = {
            'saadparwaiz1/cmp_luasnip',
        },
        config = function()
            local cmp = require('cmp')
            cmp.setup({
                sources = cmp.config.sources({
                    { name = 'luasnip' }
                })
            })
        end
    }
})
  1. Type an emoji (like 😀) or CJK character (like 一) in insert mode
  2. Return to normal mode
  3. Shift+o and type d

A popup menu with catppuccin theme causes the crash.

Crash01.mp4

Crash 2

/usr/lib/zig/std/debug.zig:403:14: 0x17c775c in assert (ghostty)
    if (!ok) unreachable; // assertion failure
             ^
src/terminal/PageList.zig:1933:11: 0x1a51fb1 in erasePage (ghostty)
    assert(page.next != null or page.prev != null);
          ^
src/terminal/PageList.zig:1857:27: 0x1a0b59a in eraseRows (ghostty)
            self.erasePage(chunk.page);
                          ^
src/terminal/Screen.zig:488:29: 0x1a701f8 in cursorDownScroll (ghostty)
        self.pages.eraseRows(.{ .active = .{} }, .{ .active = .{} });
                            ^
src/terminal/Terminal.zig:1055:45: 0x1a70cfb in index (ghostty)
            try self.screen.cursorDownScroll();
                                            ^
src/termio/Exec.zig:1963:32: 0x1b619ad in linefeed (ghostty)
        try self.terminal.index();
                               ^
src/terminal/stream.zig:344:46: 0x1b61b9f in execute (ghostty)
                    try self.handler.linefeed()
                                             ^
src/terminal/stream.zig:94:41: 0x1b85ef7 in nextSliceCapped (ghostty)
                        try self.execute(@intCast(cp));
                                        ^
src/terminal/stream.zig:60:41: 0x1b8665f in nextSlice (ghostty)
                try self.nextSliceCapped(input[i .. i + len], &cp_buf);
                                        ^
src/termio/Exec.zig:1636:41: 0x1b44c06 in threadMainPosix (ghostty)
            ev.terminal_stream.nextSlice(buf) catch |err|
                                        ^
/usr/lib/zig/std/Thread.zig:406:13: 0x1b00e83 in callFn__anon_163769 (ghostty)
            @call(.auto, f, args);
            ^
/usr/lib/zig/std/Thread.zig:674:30: 0x1aad4e2 in entryFn (ghostty)
                return callFn(f, args_ptr.*);
                             ^

Repro

Just resize the window to a horizontal line with nvim or less opened.

Crash02.mp4

Crash 3

Cannot reproduce.

thread panic: attempt to use null value
src/terminal/Selection.zig:200:65: 0x196930e in order (ghostty)
    const start_pt = s.pages.pointFromPin(.screen, self.start()).?.screen;
                                                                ^
src/terminal/Selection.zig:231:19: 0x18a0621 in ordered (ghostty)
    if (self.order(s) == desired) return Selection.init(
                  ^
src/terminal/Screen.zig:1228:41: 0x189e569 in selectionString (ghostty)
    const sel_ordered = opts.sel.ordered(self, .forward);
                                        ^
src/Surface.zig:1081:56: 0x18a5bb0 in setSelection (ghostty)
    const buf = self.io.terminal.screen.selectionString(self.alloc, .{
                                                       ^
src/Surface.zig:2836:30: 0x18e5160 in dragLeftClickSingle (ghostty)
        try self.setSelection(terminal.Selection.init(
                             ^
src/Surface.zig:2645:46: 0x18ea066 in cursorPosCallback (ghostty)
            1 => try self.dragLeftClickSingle(pin, pos.x),
                                             ^
src/Surface.zig:1437:31: 0x18f4af5 in keyCallback (ghostty)
        self.cursorPosCallback(pos) catch {};
                              ^
src/apprt/gtk/Surface.zig:1471:49: 0x18e11cc in keyEvent (ghostty)
    const effect = self.core_surface.keyCallback(.{
                                                ^
src/apprt/gtk/Surface.zig:1204:24: 0x1862610 in gtkKeyPressed (ghostty)
    return if (keyEvent(.press, ec_key, keyval, keycode, gtk_mods, ud)) 1 else 0;
                       ^
???:?:?: 0x78ab0227e93b in ??? (libgtk-4.so.1)

Crash 4

Ghostty 0.1.0-paged-terminal+612b929

src/terminal/Screen.zig:759:43: 0x1a0b92a in clearCells (ghostty)
                self.cursor.style_ref.?.* -= 1;
                                          ^
src/terminal/Screen.zig:506:24: 0x1a70b6e in cursorDownScroll (ghostty)
        self.clearCells(
                       ^
src/terminal/Terminal.zig:1051:45: 0x1a715db in index (ghostty)
            try self.screen.cursorDownScroll();
                                            ^
src/termio/Exec.zig:1963:32: 0x1b624bd in linefeed (ghostty)
        try self.terminal.index();
                               ^
src/terminal/stream.zig:344:46: 0x1b626af in execute (ghostty)
                    try self.handler.linefeed()
                                             ^
src/terminal/stream.zig:94:41: 0x1b86a47 in nextSliceCapped (ghostty)
                        try self.execute(@intCast(cp));
                                        ^
src/terminal/stream.zig:60:41: 0x1b871af in nextSlice (ghostty)
                try self.nextSliceCapped(input[i .. i + len], &cp_buf);
                                        ^
src/termio/Exec.zig:1636:41: 0x1b45716 in threadMainPosix (ghostty)
            ev.terminal_stream.nextSlice(buf) catch |err|
                                        ^
/usr/lib/zig/std/Thread.zig:406:13: 0x1b01763 in callFn__anon_163779 (ghostty)
            @call(.auto, f, args);
            ^
/usr/lib/zig/std/Thread.zig:674:30: 0x1aaddc2 in entryFn (ghostty)
                return callFn(f, args_ptr.*);
                             ^

Repro

Almost the same step as crash 2 but with a difference that the document has a CJK character or emoji.

Cannot reproduce it if using nvim --clean.

An asciinema is here (recorded directly from paged-terminal), but if you play it you may get crash 1 (with --command="fish --no-config") or nothing happened.

Crash04.mp4
@mitchellh
Copy link
Contributor

For crash 1, can you get an asciinema from a working Ghostty build (or any terminal) and post that here? I think that may be an easier way to reproduce since getting a person's entire neovim config working is a huge pain, and I've been working in neovim daily in the paged-terminal build without issue.

For crash 2, that's interesting. I can see for sure that there are problems with tiny windows. I didn't notice this because macOS has a minimum window size!

Crash 3, I'll try to make selections to reproduce.

@mitchellh
Copy link
Contributor

Crash 2 fixed, good bug: c3e90b8

Thanks!

@mitchellh
Copy link
Contributor

Related to crash 2, I'm no longer getting a crash, but when I reduce the size of the window to zero and then increase the window size again, Ghostty hangs. I haven't tracked this down yet.

@mitchellh
Copy link
Contributor

Fixed that issue! 25bcbcd

@mitchellh
Copy link
Contributor

I can't reproduce your other issues unfortunately. I asked for one clarification for crash 1, if you can try to provide that I'll give it a shot. I totally believe they exist just need a reproducer. :)

@KNnut
Copy link
Collaborator Author

KNnut commented Mar 21, 2024

This record can be used to reproduce crash 1 for me in ghostty paged-terminal+c0ca063.

asciinema play crash01.json

@mitchellh
Copy link
Contributor

That reproduces it thank you ❤️

@KNnut
Copy link
Collaborator Author

KNnut commented Mar 21, 2024

Get a new crash (Crash 4) while testing crash 1 and 2.

@mitchellh
Copy link
Contributor

I have a strong suspicion that crash 4 is the same bug as crash 1 but when it manifests on the IO thread instead of the renderer thread. We’ll see!

@KNnut
Copy link
Collaborator Author

KNnut commented Mar 21, 2024

I found a simple way to cause crash 1: just type a CJK character or emoji in helix and then delete it.

@mitchellh
Copy link
Contributor

Fixed crash 1 and crash 4: 30f112e They were the same.

@mitchellh
Copy link
Contributor

I'm confident crash 3 still exists, but without a repro it will be very hard to fix. I tried clicking and dragging around and selecting text and wasn't able to reproduce it. If you can figure that out, please open a new issue and post the repro.

Because all the other issues are now resolved, I'm going to close this. Please advise if I'm mistaken! And thank you!

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

No branches or pull requests

2 participants