Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(native): the RGBA32 fallback asks basis for pixels, not for blocks

esengineb3eeb2b2c571
diff --git a/native/host/media/ktx2_decode.cpp b/native/host/media/ktx2_decode.cpp
index f73bc19bd..3db32b668 100644
--- a/native/host/media/ktx2_decode.cpp
+++ b/native/host/media/ktx2_decode.cpp
@@ -73,10 +73,10 @@ KTX2Result transcodeKTX2(const uint8_t* bytes, size_t n, bool srgb,
break;
}
- // A compressed texture keeps the KTX2's pre-baked mip chain (basis cannot
- // generate mips for block formats); the RGBA32 fallback uploads base only.
- // output_blocks_buf_size counts blocks (block formats) or pixels (RGBA32);
- // block_width/height is 1 for RGBA32, so this covers both.
+ // The output count is BLOCKS for a block format and PIXELS for an uncompressed
+ // one: basis reports a 4x4 block for RGBA32 too, so one formula does not cover
+ // both — 324 units of a 70x70 image is a decode that fails.
+ const bool uncompressed = basist::basis_transcoder_format_is_uncompressed(basisFmt);
const uint32_t bw = basist::basis_get_block_width(basisFmt);
const uint32_t bh = basist::basis_get_block_height(basisFmt);
const uint32_t bpb = basist::basis_get_bytes_per_block_or_pixel(basisFmt);
@@ -93,7 +93,8 @@ KTX2Result transcodeKTX2(const uint8_t* bytes, size_t n, bool srgb,
for (uint32_t level = 0; level < numLevels; ++level) {
const uint32_t lw = (w >> level) ? (w >> level) : 1u;
const uint32_t lh = (h >> level) ? (h >> level) : 1u;
- const uint32_t units = ((lw + bw - 1) / bw) * ((lh + bh - 1) / bh);
+ const uint32_t units = uncompressed ? (lw * lh)
+ : ((lw + bw - 1) / bw) * ((lh + bh - 1) / bh);
const size_t off = out.size();
out.resize(off + static_cast<size_t>(units) * bpb);
if (!t.transcode_image_level(level, 0, 0, out.data() + off, units, basisFmt)) {
diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjs
index c710d647a..936c3b702 100644
--- a/tools/goldenProjects.mjs
+++ b/tools/goldenProjects.mjs
@@ -155,9 +155,9 @@ export const GOLDEN = [
targets: ['web', 'desktop', 'android'],
tier: 'pr',
interact: { keys: ['ArrowRight'], frames: 40 },
- // A KTX2 that is not whole 4x4 blocks, on purpose: WebGPU refuses one, and a
- // single failed texture blanks the frame — so the desktop run guards
- // ktx2_decode.cpp's fallback. The cook only encodes .png, so this passes through.
+ // A KTX2 that is not whole 4x4 blocks, on purpose, so ktx2_decode.cpp falls back
+ // to RGBA32. What LOADS it is the native boot smoke (it packages every asset);
+ // check-golden only holds the file to its odd size.
oddSizedKtx2: 'assets/textures/block-guard.ktx2',
// Two textured platforms and the sky behind them. Measured over three runs
// and stable to the byte; the falling player is NOT, which is why it is not