bevyengine / bevyengine/bevy

Bytes per pixel should be multiplied by width before calling align_copy_bytes_per_row

Open
#17,357 0 comments 0 reactions 0 assignees View on GitHub
A-Rendering C-Bug D-Straightforward S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

I was playing around with the headless_renderer.rs example. I observed that `image_data` received in the update system was 4x the size I was expecting. I set the dimensions to 64x64 in AppConfig; image_data.len was 65k bytes vs the expected 16k.

I think it's due how the cpu buffer is initialized in ImageCopier::new()

```
pub fn new(
src_image: Handle,
size: Extent3d,
render_device: &RenderDevice,
) -> ImageCopier {
let padded_bytes_per_row =
RenderDevice::align_copy_bytes_per_row((size.width) as usize) * 4; // HERE: shouldn't we multiply by 4 before calling align_copy_bytes_per_row?

let cpu_buffer = render_device.create_buffer(&BufferDescriptor {
label: None,
size: padded_bytes_per_row as u64 * size.height as u64,
usage: BufferUsages::MAP_READ | BufferUsages::COPY_DST,
mapped_at_creation: false,
});

ImageCopier {
buffer: cpu_buffer,
src_image,
enabled: Arc::new(AtomicBool::new(true)),
}
}
```

When I make the suggested change, I get the expected image_data length.

I'm relatively new to rendering code, so wanted to confirm this is an error first. If it is, I can submit a simple PR to fix.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.