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

Panic when exiting search #5632

Open
par5er opened this issue Jan 22, 2023 · 3 comments
Open

Panic when exiting search #5632

par5er opened this issue Jan 22, 2023 · 3 comments
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@par5er
Copy link

par5er commented Jan 22, 2023

Summary

Editor panics when exiting search

Reproduction Steps

I tried this:

  1. hx .
  2. Open a small file
  3. Make a vertical split and open a larger file in the second pane
  4. Search for something in the larger file and hit ENTER
  5. Search for something again, and this time switch to the first pane without closing the search dialog
  6. Hit ESCAPE and the program crashes

I expected this to happen:
The search dialog to close

Instead, this happened:
https://asciinema.org/a/eLc59nJruhSfKI2qW7whCK5ig

Helix log

~/.cache/helix/helix.log
please provide a copy of `~/.cache/helix/helix.log` here if possible, you may need to redact some of the lines

Platform

Linux (Debian 11)

Terminal Emulator

st

Helix Version

helix 22.12 (7ac72a3)

@par5er par5er added the C-bug Category: This is a bug label Jan 22, 2023
@archseer
Copy link
Member

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace    

@the-mikedavis
Copy link
Member

I can reproduce this. On a debug build the backtrace is:

thread 'main' panicked at 'assertion failed: char_idx <= slice.len_chars()', helix-core/src/graphemes.rs:37:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::panicking::panic
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:48:5
   3: helix_core::graphemes::nth_prev_grapheme_boundary
             at ./helix-core/src/graphemes.rs:37:5
   4: helix_core::graphemes::prev_grapheme_boundary
             at ./helix-core/src/graphemes.rs:79:5
   5: helix_core::graphemes::ensure_grapheme_boundary_prev
             at ./helix-core/src/graphemes.rs:194:9
   6: helix_core::selection::Range::grapheme_aligned
             at ./helix-core/src/selection.rs:271:17
   7: helix_core::selection::Selection::ensure_invariants::{{closure}}
             at ./helix-core/src/selection.rs:586:28
   8: helix_core::selection::Selection::transform
             at ./helix-core/src/selection.rs:574:22
   9: helix_core::selection::Selection::ensure_invariants
             at ./helix-core/src/selection.rs:586:9
  10: helix_view::document::Document::set_selection
             at ./helix-view/src/document.rs:742:30
  11: helix_term::ui::regex_prompt::{{closure}}
             at ./helix-term/src/ui/mod.rs:105:29
  12: <alloc::boxed::Box<F,A> as core::ops::function::FnMut<Args>>::call_mut
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1868:9
  13: <helix_term::ui::prompt::Prompt as helix_term::compositor::Component>::handle_event
             at ./helix-term/src/ui/prompt.rs:566:21
  14: helix_term::compositor::Compositor::handle_event
             at ./helix-term/src/compositor.rs:143:19
  15: helix_term::application::Application::handle_terminal_events::{{closure}}
             at ./helix-term/src/application.rs:632:22
  16: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  17: helix_term::application::Application::event_loop_until_idle::{{closure}}
             at ./helix-term/src/application.rs:347:55
  18: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  19: helix_term::application::Application::event_loop::{{closure}}
             at ./helix-term/src/application.rs:326:57
  20: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  21: helix_term::application::Application::run::{{closure}}
             at ./helix-term/src/application.rs:1073:38
  22: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  23: hx::main_impl::{{closure}}
             at ./helix-term/src/main.rs:156:53
  24: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  25: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/park.rs:283:63
  26: tokio::runtime::coop::with_budget
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/coop.rs:102:5
  27: tokio::runtime::coop::budget
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/coop.rs:68:5
  28: tokio::runtime::park::CachedParkThread::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/park.rs:283:31
  29: tokio::runtime::context::BlockingRegionGuard::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/context.rs:315:13
  30: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/scheduler/multi_thread/mod.rs:66:9
  31: tokio::runtime::runtime::Runtime::block_on
             at /home/michael/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.24.1/src/runtime/runtime.rs:284:45
  32: hx::main_impl
             at ./helix-term/src/main.rs:158:5
  33: hx::main
             at ./helix-term/src/main.rs:38:21
  34: core::ops::function::FnOnce::call_once
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

When switching windows I think we want to cancel out of the prompt first. It looks like we're trying to jump to the next search match and if the split's file is shorter than the search file, we get a panic.

@pascalkuthe
Copy link
Member

pascalkuthe commented Jan 23, 2023

I can also reproduce. The same crash also happens for other prompts like s or k.

I think the correct fix for this would be to call Composistor::remove(..) (with a new id returned by prompt.id()) in Editor::_refresh.
The problem is that we can't do that because the compositor is currently in helix-term so a fix is also blocked on #5555/#5581.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

5 participants