From f6d624be8f22c1d67bf6fd498fd4ee32d9b7e487 Mon Sep 17 00:00:00 2001 From: rextimmy Date: Mon, 16 Jan 2017 15:36:52 +1000 Subject: [PATCH] Fix mipmap count and potential crash for non square textures that are allocated with GBitmap class --- Engine/source/gfx/bitmap/gBitmap.cpp | 5 ++++- Engine/source/gfx/gfxTextureManager.cpp | 16 +--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Engine/source/gfx/bitmap/gBitmap.cpp b/Engine/source/gfx/bitmap/gBitmap.cpp index e5ef6b407..9e20d6951 100644 --- a/Engine/source/gfx/bitmap/gBitmap.cpp +++ b/Engine/source/gfx/bitmap/gBitmap.cpp @@ -327,7 +327,10 @@ void GBitmap::allocateBitmap(const U32 in_width, const U32 in_height, const bool mNumMipLevels++; allocPixels += currWidth * currHeight * mBytesPerPixel; - } while (currWidth != 1 && currHeight != 1); + } while (currWidth != 1 || currHeight != 1); + + U32 expectedMips = mFloor(mLog2(mMax(in_width, in_height))) + 1; + AssertFatal(mNumMipLevels == expectedMips, "GBitmap::allocateBitmap: mipmap count wrong"); } AssertFatal(mNumMipLevels <= c_maxMipLevels, "GBitmap::allocateBitmap: too many miplevels"); diff --git a/Engine/source/gfx/gfxTextureManager.cpp b/Engine/source/gfx/gfxTextureManager.cpp index b656fcffd..781e0daa2 100644 --- a/Engine/source/gfx/gfxTextureManager.cpp +++ b/Engine/source/gfx/gfxTextureManager.cpp @@ -1085,21 +1085,7 @@ void GFXTextureManager::_validateTexParams( const U32 width, const U32 height, // NOTE: Does this belong here? if( inOutNumMips == 0 && !autoGenSupp ) { - U32 currWidth = width; - U32 currHeight = height; - - inOutNumMips = 1; - do - { - currWidth >>= 1; - currHeight >>= 1; - if( currWidth == 0 ) - currWidth = 1; - if( currHeight == 0 ) - currHeight = 1; - - inOutNumMips++; - } while ( currWidth != 1 && currHeight != 1 ); + inOutNumMips = mFloor(mLog2(mMax(width, height))) + 1; } } } -- 2.11.4.GIT