thread 'main' panicked
Following the tutorial on Hands-on Rust I found that compiling flappy I get this error:
thread 'main' panicked at library/core/src/panicking.rs:221:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted (core dumped)
I do not use nightly rust, and my setup was completely following the book. Searching online I found this issue https://github.com/KyleMayes/vulkanalia/issues/254. Could it be related somehow?
I have a project that was working yesterday and today is having this issue. From stackoverflow
A recent change to the standard library enabled debug assertions in core/std to fire if the user compiles in debug mode
That appears to be on rust 1.78, I downgrade my project to 1.77.1 (not sure why 1.77.2 toolchain fail to install):
rustup install 1.77.1
echo "1.77.1" > rust-toolchain
The workarounds appears to be:
- You need to wait for a fix (not sure where)
- compile on release mode
- use a older toolchain < 1.78
This appears related to the wayland backend on linux, at least it was for me. You can also workaround this error by running it via the x11 winit backend x11: WINIT_UNIX_BACKEND=x11 cargo run
I'm not sure why this is failing, since the winit examples run fine for me in wayland.
Ah, I've traced it down to the glutin version that is tagged. When I try to run the window example in glutin v0.29.1 I get the same error from glutin:
thread 'main' panicked at library/core/src/panicking.rs:219:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted
The glutin examples work fine at the latest version. Not sure how easy that is to upgrade, but it could just be a version change.
Having the same issue on Ubuntu 24.04 LTS
cargo run error :
thread 'main' panicked at library/core/src/panicking.rs:218:5: unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed isize::MAX
Stack Trace Attached.
Same on UBUNTU 24.04 LTS
Same on NixOS, again under wayland. I'll try using X11 but I don't believe I actually have any X11 running on my machine.
I am having the same error.
This appears related to the wayland backend on linux, at least it was for me. You can also workaround this error by running it via the x11 winit backend x11:
WINIT_UNIX_BACKEND=x11 cargo runI'm not sure why this is failing, since the winit examples run fine for me in wayland.
This has solved the error.
See also #373