From 65c9f44a2fcaf542c1d88a8abafc3b5f3ae5fba7 Mon Sep 17 00:00:00 2001 From: Oleksandr Shyshatskyi Date: Wed, 9 Apr 2025 18:40:20 +0300 Subject: [PATCH] Fix incorrect mipmap size calculation for uncompressed DDS textures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the DDS texture loader incorrectly calculated mipmap dimensions for uncompressed textures when the original dimensions were non-power-of-two. For example, given a 120×120 texture, the expected mipmap chain should be: mipmap=0, size=120×120 mipmap=1, size=60×60 mipmap=2, size=30×30 mipmap=3, size=15×15 mipmap=4, size=7×7 mipmap=5, size=3×3 mipmap=6, size=1×1 But the loader was producing: mipmap=0, size=120×120 mipmap=1, size=60×60 mipmap=2, size=30×30 mipmap=3, size=15×15 mipmap=4, size=8×8 mipmap=5, size=4×4 mipmap=6, size=2×2 This commit corrects the logic to properly compute width and height independently at each mip level. Fixes issue #105136. --- modules/dds/texture_loader_dds.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 1fd7e517055..c360dd8892b 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -165,8 +165,8 @@ static Ref _dds_load_layer(Ref p_file, DDSFormat p_dds_format uint32_t size = p_width * p_height * info.block_size; for (uint32_t i = 1; i < p_mipmaps; i++) { - w = (w + 1) >> 1; - h = (h + 1) >> 1; + w = MAX(1u, w >> 1); + h = MAX(1u, h >> 1); size += w * h * info.block_size; }