bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.39k stars 3.59k forks source link

Calling `Image::get_color_at` panics #16474

Closed andriyDev closed 2 days ago

andriyDev commented 3 days ago

On #16388, we are using Image::get_color_at to determine a pixel's alpha value. There is no unwrap occuring, so we expect there to be no panics, however another user noted the following:

Testing the changes got this error after a crash:

2024-11-22T07:39:32.137594Z  INFO bevy_winit::system: Creating new window "App" (0v1#4294967296)
2024-11-22T07:39:32.137772Z  INFO winit::platform_impl::platform::x11::window: Guessed window scale factor: 1
2024-11-22T07:39:32.326951Z  WARN bevy_render::view::window: Couldn't get swap chain texture after configuring. Cause: 'The underlying surface has changed, and therefore the swap chain must be updated'
thread 'Compute Task Pool (4)' panicked at /home/adrian/bevy_testing/bevy/crates/bevy_image/src/image.rs:974:36:
range end index 8 out of range for slice of length 4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_sprite::picking_backend::sprite_picking`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

I'm using 0.15 release branch with the changes applied on top. Running the sprite_picking example The sprite on the right works fine, but the squares and bevy logos works quite bad and make the app crash. The test run on linux with x11 as you can see in the errors

Originally posted by @MonforteAdrian in https://github.com/bevyengine/bevy/issues/16388#issuecomment-2493084194