maras-archive / rsnake

Snake implemented in rust.
MIT License
136 stars 30 forks source link

thread 'main' panicked at 'attempted to leave type `std::mem::ManuallyDrop<xlib::Xlib>` uninitialized, which is invalid' #5

Open laszukdawid opened 2 years ago

laszukdawid commented 2 years ago

I'm new to Rust development and thought that modifying snake would be a nice starting project.

Just cloned repo, downloaded dependencies, built it and tried to run. There wasn't any error on cargo run and cargo build --release, only a few formatting warnings. When trying to run produced binary, I'm getting the error below. Any chance you could help figure out the issue?

By the trace it seems the problem is with Xlib. Does it need to be in specific version? Is it even Ok for linux?

System: Ubuntu 20.04 (Linux meland 5.11.0-43-generic #47~20.04.2-Ubuntu SMP Mon Dec 13 11:06:56 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux) Cargo: cargo 1.54.0 (5ae8d74b3 2021-06-22)

Backtrace:

kretyn@meland:~/projects/rsnake$ RUST_BACKTRACE=1 ./target/release/rsnake 
thread 'main' panicked at 'attempted to leave type `std::mem::ManuallyDrop<xlib::Xlib>` uninitialized, which is invalid', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/mem/mod.rs:660:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:50:5
   3: x11_dl::xlib::Xlib::open
   4: winit::platform::platform::x11::xdisplay::XConnection::new
   5: std::sync::once::Once::call_once::{{closure}}
   6: std::sync::once::Once::call_inner
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sync/once.rs:418:21
   7: winit::platform::platform::EventsLoop::new_x11
   8: winit::platform::platform::EventsLoop::new
   9: winit::EventsLoop::new
  10: glutin_window::GlutinWindow::new
  11: <glutin_window::GlutinWindow as window::BuildFromWindowSettings>::build_from_window_settings
  12: <piston_window::PistonWindow<W> as window::BuildFromWindowSettings>::build_from_window_settings
  13: rsnake::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
kretyn@meland:~/projects/rsnake$ 
laszukdawid commented 2 years ago

I'm new to Rust and piston_window so I'm not really sure what is the problem specifically. My guess is Xlib had some API update and that is incompatible with older version of piston_window (this package uses 0.85.0). Updating to the newest version and fixing some code has fixed the issue. Here's the commit that introduces fix https://github.com/laszukdawid/rsnake/commit/5438ef559eb29b100595ff83d81cafa26a1ceca7.