amethyst / amethyst/bracket-lib
thread 'main' panicked at 'index out of bounds when using crossterm as the backend
- 主要言語
- Rust
- スター
- 1.7k
- フォーク
- 126
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I've been unable to use crossterm as my backend for bracket-lib, getting a compile error even when trying one of the examples.
I initially thought that this issue could be related to #256 but that issue seems specifically about how to get bracket to use crossterm instead of a opengl window, so I'm opening an issue for my specific error.
This is my minimal setup that seems to be able to reproduce my issue:
rustup toolchain: stable-x86_64-unknown-linux-gnu (default)
rustc version: rustc 1.57.0 (f1edd0429 2021-11-29)
cargo version: cargo 1.57.0 (b2e52d7ca 2021-10-21)
Linux kernel: Linux 5.13.0-27-generic x86_64
Ubuntu version: Ubuntu 21.10 Iimpish Idri
$TERM: xterm
Shell: zsh
Cargo.toml
```toml
[package]
name = "bracket-test"
version = "0.1.0"
edition = "2021"
resolver = "2"
[dependencies]
bracket-terminal = { git = "https://github.com/amethyst/bracket-lib.git", version = "0.8.1", default-features = false, features = ["cross_term"] }
legion = { version = "0.4.0", default-features = false, features = ["wasm-bindgen"] }
lazy_static = "1.4.0"
```
sample main.rs to reproduce:
```rust
use bracket_terminal::prelude::*;
bracket_terminal::add_wasm_support!();
struct State {}
impl GameState for State {
fn tick(&mut self, ctx: &mut BTerm) {
ctx.print(1, 1, "Hello Bracket World");
}
}
fn main() -> BError {
let context = BTermBuilder::simple80x50()
.with_title("Hello Minimal Bracket World")
.build()?;
let gs: State = State {};
main_loop(context, gs)
}
```
Note: The above code is a copy paste from the hello_minimal.rs
The error I get is this:
```
cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/bracket-test`
thread 'main' panicked at 'index out of bounds: the len is 8930 but the index is 9310', /home/user/.cargo/git/checkouts/bracket-lib-bcfc6f411b633b6a/5e35a05/bracket-terminal/src/hal/crossterm_be/main_loop.rs:233:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
and the full backtrace:
```
Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/bracket-test`
thread 'main' panicked at 'index out of bounds: the len is 1840 but the index is 3920',
/home/user/.cargo/git/checkouts/bracket-lib-bcfc6f411b633b6a/5e35a05/bracket-terminal/src/hal/crossterm_be/main_loop.rs:233:25
stack backtrace:
0: rust_begin_unwind at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
2: core::panicking::panic_bounds_check at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:76:5
3: >::index_mut at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/slice/index.rs:190:14
4: core::slice::index:: for [T]>::index_mut at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/slice/index.rs:26:9
5: as core::ops::index::IndexMut>::index_mut at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/alloc/src/vec/mod.rs:2508:9
6: bracket_terminal::hal::crossterm_be::main_loop::full_redraw at /home/aimeri/.cargo/git/checkouts/bracket-lib-bcfc6f411b633b6a/5e35a05/bracket-terminal/src/hal/crossterm_be/main_loop.rs:233:25
7: bracket_terminal::hal::crossterm_be::main_loop::main_loop sterm_be/main_loop.rs:140:34
8: bracket_terminal::bterm::main_loop at /home/aimeri/.cargo/git/checkouts/bracket-lib-bcfc6f411b633b6a/5e35a05/bracket-terminal/src/bterm.rs:1083:5
9: bracket_test::main at ./src/main.rs:43:5
10: core::ops::function::FnOnce::call_once at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
so it seems like on line 233 of main_loop.rs for crossterm_be this line is called:
```rust
buffer[buf_idx].glyph = to_char(t.glyph as u8);
```
which means that `buffer.len() == 8930` and `buf_idx == 9310`.
seems like buf_idx is calculated by this line
```rust
let mut buf_idx = (st.height as u16 - (y as u16 + 1)) as usize * width as usize;
```
on my machine the values from width and height are as follow when executing my application:
```
st.height == 50
st.width == 80
width == 190
height == 47
```
that means on first iteration of the loops in `partial_redraw` the buf_idx ends up being calculate as `(50 - (0 + 1)) * 190 = 9310` but buffer is `190 * 47 = 8930` as per
```
let mut buffer = vec![OutputBuffer::default(); height as usize * width as usize];
# same as vec![OutputBuffer::default(); 8930];
```
I'm glad to help troubleshoot this in any way I can, so feel free to ask for any additional information I can provide to help troubleshoot. I'm not afraid to jump in to the code in the library to get some debug outputs as well, so if that's helpful in anyway let me know.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
評価
この issue はまだ評価されていません。