From 2c8533661bebb4c2ee1b24e6187c1efee9ec4453 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 18 Dec 2021 23:46:47 +0700 Subject: [PATCH] Fix crash in Mario Tennis, caused by wrong tile size calculation. Regressions in S2DEX games are possible, but not found yet. Also make sure that size of mip-map tile is not greater than possible. --- src/Textures.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Textures.cpp b/src/Textures.cpp index 8e5831ef..828a5bcc 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -637,8 +637,9 @@ void _calcTileSizes(u32 _t, TileSizes & _sizes, gDPTile * _pLoadTile) // 32 bit texture loaded into lower and upper half of TMEM, thus actual bytes doubled. info.bytes *= 2; } - gDP.loadTile->loadWidth = gDP.loadTile->loadHeight = 0; } + + gDP.loadTile->loadWidth = gDP.loadTile->loadHeight = 0; _sizes.bytes = info.bytes; if (tileWidth == 1 && tileHeight == 1 && @@ -1447,8 +1448,8 @@ void TextureCache::_loadAccurate(u32 _tile, CachedTexture *_pTexture) tmptex.size = mipTile.size; TileSizes sizes; _calcTileSizes(tileMipLevel, sizes, nullptr); - tmptex.width = sizes.width; - tmptex.height = sizes.height; + tmptex.width = std::min(tmptex.width, static_cast(sizes.width)); + tmptex.height = std::min(tmptex.height, static_cast(sizes.height)); tmptex.clampWidth = sizes.clampWidth; tmptex.clampHeight = sizes.clampHeight; _pTexture->textureBytes += (tmptex.width * tmptex.height) << sizeShift;