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 using check_for_event #313

Open
Soupstraw opened this issue Nov 7, 2020 · 11 comments
Open

Panic when using check_for_event #313

Soupstraw opened this issue Nov 7, 2020 · 11 comments

Comments

@Soupstraw
Copy link

I tried to use the check_for_event function, but got this error:

32bits font... checking for alpha layer... not present
key color : 0 0 0
thread 'main' panicked at 'attempted to leave type `bindings::ffi::TCOD_key_t` uninitialized, which is invalid', /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/mem/mod.rs:659:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:483:5
   1: core::panicking::panic_fmt
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/panicking.rs:85:14
   2: core::panicking::panic
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/panicking.rs:50:5
   3: core::mem::uninitialized
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/mem/mod.rs:659:9
   4: tcod::input::check_for_event
             at [..]/.cargo/registry/src/github.com-1ecc6299db9ec823/tcod-0.15.0/src/input.rs:193:53
   5: rustrogue::handle_keys
             at ./src/main.rs:70:21
   6: rustrogue::main
             at ./src/main.rs:48:20
   7: core::ops::function::FnOnce::call_once
             at [..]/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I am using the Rust nightly toolchain, if that's somehow related.

@Soupstraw
Copy link
Author

Soupstraw commented Nov 7, 2020

This seems to be specific to the nightly toolchain, works fine with stable.

@Soupstraw Soupstraw changed the title Segfault when using check_for_event Panic when using check_for_event Nov 13, 2020
@grkuntzmd
Copy link

grkuntzmd commented Dec 5, 2020

I am getting the same error using the stable toolchain (stable-x86_64-pc-windows-msvc (default)).
rustc 1.48.0 (7eac88abb 2020-11-16)

@tomassedovic
Copy link
Owner

tomassedovic commented Dec 6, 2020

Sorry for the delay in replying! I've been able to reproduce this on Linux with Rust rustc 1.48.0 (7eac88abb 2020-11-16) as well:

$ cargo run --example samples
thread 'main' panicked at 'attempted to leave type `bindings::ffi::TCOD_key_t` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

There's also this warning during compilation:

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/input.rs:193:53
    |
193 |     let mut c_key_state: ffi::TCOD_key_t = unsafe { mem::uninitialized() };

Switching all uses of unitialized!() will hopefully fix this. MaybeUninit. Unfortunately, I don't have the time/energy to maintain this project anymore. I've just opened a readme update that makes that explicit: #314.

If you open a fix, I'll merge it, but it may be better to try one of the newer and more powerful libraries instead:

@ojhp
Copy link
Collaborator

ojhp commented Jan 11, 2021

I've raised #315 if anyone's available to merge.

This replaces the deprecated calls with MaybeUninit. Tests all still pass and the examples now all seem to run properly.

@ojhp
Copy link
Collaborator

ojhp commented Jan 11, 2021

While looking at this I noticed there's a couple of other bits that are currently giving deprecated warnings that I'd guess will break in later versions of rust:

  • Inclusive ranges using ... instead of ..=
  • Something I don't understand in the lazy_static! macro that seems to be fixed by updating the dependency

If wanted I can push fixes for those too.

marcdel added a commit to marcdel/roguelike that referenced this issue May 11, 2021
also points the tcod dependency to github where a fix has been merged. a new version of the crate hasn't been released yet.
tomassedovic/tcod-rs#313
@rhighs
Copy link

rhighs commented Nov 26, 2021

Hi, switching to mem::MaybeUninit doesn't seem to do much, i get the same error on both stable and nightly toolchain

thread 'main' panicked at 'attempted to leave type `tcod_sys::TCOD_key_t` uninitialized, which is invalid', /home/rob/.cargo/registry/src/github.com-1ecc6299db9ec823/tcod-0.15.0/src/input.rs:193:53

Line 193:

let mut c_key_state: mem::MaybeUninit<ffi::TCOD_key_t> = mem::MaybeUninit::uninit();

Why not just using an Option<ffi::TCOD_key_t>?

@hfiguiere
Copy link

I'm hitting this by following the tutorial about Rogue Like.

https://tomassedovic.github.io/roguelike-tutorial/part-7-gui.html

(I'm putting this in case someone go through the tutorial and reach the same issue)

@giulio-Joshi
Copy link

For anyone that would like to finish the tutorial as exercise, switching to master branch in cargo worked for me (at least, for this specific issue).

[dependencies]
#tcod = "0.15"
tcod = { git= "https://github.com/tomassedovic/tcod-rs.git"}

@Opayne93
Copy link

Opayne93 commented Mar 8, 2022

Switching to master seems to solve the error, but for some odd reason, there is an occasional input stick. It's like something isn't registering a key release...

@Just-a-Unity-Dev
Copy link

Switching to master seems to solve the error, but for some odd reason, there is an occasional input stick. It's like something isn't registering a key release...

Getting the same error

@john-science
Copy link

As @giulio-Joshi said above, I fixed this by changing my Cargo.toml to:

[dependencies]
tcod = { git = "https://github.com/tomassedovic/tcod-rs.git", rev = "d4ad074"}

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

10 participants