bracket-lib icon indicating copy to clipboard operation
bracket-lib copied to clipboard

thread 'main' panicked

Open carlolalu opened this issue 1 year ago • 7 comments

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?

carlolalu avatar Sep 11 '24 22:09 carlolalu

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:

  1. You need to wait for a fix (not sure where)
  2. compile on release mode
  3. use a older toolchain < 1.78

sisso avatar Sep 21 '24 13:09 sisso

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.

MichaelMackus avatar Oct 24 '24 19:10 MichaelMackus

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.

MichaelMackus avatar Oct 24 '24 20:10 MichaelMackus

message.txt

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.

Ronin15 avatar Feb 21 '25 14:02 Ronin15

Same on UBUNTU 24.04 LTS

davimouravilaca avatar Mar 20 '25 12:03 davimouravilaca

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.

garry-cairns avatar May 12 '25 17:05 garry-cairns

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 run

I'm not sure why this is failing, since the winit examples run fine for me in wayland.

This has solved the error.

Aganthor avatar May 23 '25 17:05 Aganthor

See also #373

brianpeiris avatar Dec 26 '25 23:12 brianpeiris