Crash if KTX2 images are "unaligned" sizes
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
`main`: 8067e46049f222d37ac394745805bad98979980f
## What you did
I made a test program which takes an image asset path as arg and loads it.
Run it like: `cargo run --example ktx2_test -F basis-universal -F zlib -- image.ktx2`
```rust
use bevy::prelude::*;
#[derive(Debug, Resource)]
struct ImagePath(String);
fn main() {
// Take a name such as "image.ktx2" as the first arg, will then load "bevy/assets/image.ktx2"
let i = std::env::args_os().skip(1).next().unwrap();
let i = i.to_str().unwrap().to_string();
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(ImagePath(i))
.add_systems(Startup, setup)
.run();
}
#[derive(Resource)]
struct ImageResource(Handle);
fn setup(mut commands: Commands, assets: Res, img: Res) {
commands.spawn(Camera2dBundle::default());
commands.spawn(ImageBundle {
image: UiImage {
texture: assets.load(&img.0),
..default()
},
..default()
});
}
```
## What went wrong
### what were you expecting?
It should load the image without issue.
### what actually happened?
It crashes on some `.ktx2` files.
## Additional information
### logs
```
thread 'Compute Task Pool (3)' panicked at /home/togr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.18.0/src/util/device.rs:130:26:
range end index 3009808 out of range for slice of length 3009632
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::render_asset::prepare_assets`!
thread 'Compute Task Pool (3)' panicked at crates/bevy_render/src/pipelined_rendering.rs:145:45:
called `Result::unwrap()` on an `Err` value: RecvError
```
### theories about what might be going wrong
Images with "strange" sizes is not in the happy path and is uncharted territory for testing.
### workarounds that you used
Had a hunch that the image size was the culprit due to the panic log.
So I did:
```
convert img.jpg -resize 2000x1136 img_resize.jpg
```
because the previous size `2000x1125` had a height which was not divisible by 16, so I resized the height to a close multiple of 16.
I chose 16 since it's a typical happy-path size.
Then I remade the `ktx2`:
```
# Tool from https://github.com/BinomialLLC/basis_universal
basisu -ktx2 -uastc -mipmap img_resize.jpg
```
And then the resulting `ktx2` file works.
### Source images
Attaching the original jpg as well as the resized.


### Converted images
Attaching the ktx2 files, original one that panics as well as the resized which works.
[Color_Checker.zip](https://github.com/bevyengine/bevy/files/13777899/Color_Checker.zip)
Contributor guide
Assessment
This issue has not been assessed yet.