From 37f7eab8a3195c5109a86ea09e0d7b0d88c6e7ce Mon Sep 17 00:00:00 2001 From: Ian Taylor Date: Thu, 9 Apr 2026 19:33:16 -0700 Subject: [PATCH] Fix bounds check Previous behavior: images larger that 2048px would have their bottom right corners transparent because the info didn't get uploaded to the GPU --- wgpu/src/image/atlas.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index 0432e4eb..09258329 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -347,7 +347,15 @@ impl Atlas { let stride = PIXEL * w; // bounds check for source pixels to fragment - if pixels.len() < offset + PIXEL * image_width as usize * h { + // The upload loop accesses rows 0..h; the last row starts at + // `offset + (h-1) * PIXEL * image_width` and reads `stride` bytes. + // Using `h` instead of `h-1` over-estimates by one full image_width + // row, causing false positives for bottom-right fragments whose + // x-offset is non-zero and whose bottom edge reaches the image edge. + if h > 0 + && pixels.len() + < offset + (h - 1) * PIXEL * image_width as usize + stride + { return; }