From eb459997919e7735c561fff3405db46ab5622a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Krzy=C5=9Bk=C3=B3w?= <46760021+Flower35@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:47:22 +0200 Subject: [PATCH] Fix the texture dimensions check in DynOS (#67) --- data/dynos_mgr_tex.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/data/dynos_mgr_tex.cpp b/data/dynos_mgr_tex.cpp index a8b0d4325..ca591f74d 100644 --- a/data/dynos_mgr_tex.cpp +++ b/data/dynos_mgr_tex.cpp @@ -451,8 +451,8 @@ void DynOS_Tex_AddCustom(const SysPath &aFilename, const char *aTexName) { } } -static inline bool IsPowerOfTwo(int n) { - return (ceil(log2(n)) == floor(log2(n))); +static inline bool IsPowerOfTwo(s32 n) { + return (n > 0) && ((n & (n - 1)) == 0); } bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) { @@ -487,8 +487,7 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) { return false; } // texture width or height is NPOT - if ((_Data->mRawWidth > 0 && _Data->mRawWidth & (_Data->mRawWidth - 1) == 0) || - (_Data->mRawHeight > 0 && _Data->mRawHeight & (_Data->mRawHeight - 1) == 0)) { + if (!IsPowerOfTwo(_Data->mRawWidth) || !IsPowerOfTwo(_Data->mRawHeight)) { PrintError("Tex file '%s' has non power of two width or height", aTexName); PrintConsole(CONSOLE_MESSAGE_WARNING, "Tex file '%s' has non power of two width or height", aTexName); return false;