Merged in andreyl_productengine/viewer-bear-marchcat (pull request #20)

Fixes for two image loading crashes
master
Andrey Lihatskiy 2016-10-07 19:35:50 +03:00
commit 5dd97bc2bd
3 changed files with 22 additions and 5 deletions

View File

@ -487,14 +487,15 @@ bool LLImageGL::checkSize(S32 width, S32 height)
return check_power_of_two(width) && check_power_of_two(height);
}
void LLImageGL::setSize(S32 width, S32 height, S32 ncomponents, S32 discard_level)
bool LLImageGL::setSize(S32 width, S32 height, S32 ncomponents, S32 discard_level)
{
if (width != mWidth || height != mHeight || ncomponents != mComponents)
{
// Check if dimensions are a power of two!
if (!checkSize(width,height))
{
LL_ERRS() << llformat("Texture has non power of two dimension: %dx%d",width,height) << LL_ENDL;
LL_WARNS() << llformat("Texture has non power of two dimension: %dx%d",width,height) << LL_ENDL;
return false;
}
if (mTexName)
@ -529,6 +530,8 @@ void LLImageGL::setSize(S32 width, S32 height, S32 ncomponents, S32 discard_leve
mMaxDiscardLevel = MAX_DISCARD_LEVEL;
}
}
return true;
}
//----------------------------------------------------------------------------
@ -909,7 +912,11 @@ BOOL LLImageGL::preAddToAtlas(S32 discard_level, const LLImageRaw* raw_image)
S32 h = raw_image->getHeight() << discard_level;
// setSize may call destroyGLTexture if the size does not match
setSize(w, h, raw_image->getComponents(), discard_level);
if (!setSize(w, h, raw_image->getComponents(), discard_level))
{
LL_WARNS() << "Trying to create a texture with incorrect dimensions!" << LL_ENDL;
return FALSE;
}
if( !mHasExplicitFormat )
{
@ -1273,7 +1280,11 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
S32 h = raw_h << discard_level;
// setSize may call destroyGLTexture if the size does not match
setSize(w, h, imageraw->getComponents(), discard_level);
if (!setSize(w, h, imageraw->getComponents(), discard_level))
{
LL_WARNS() << "Trying to create a texture with incorrect dimensions!" << LL_ENDL;
return FALSE;
}
if( !mHasExplicitFormat )
{

View File

@ -94,7 +94,7 @@ protected:
public:
virtual void dump(); // debugging info to LL_INFOS()
void setSize(S32 width, S32 height, S32 ncomponents, S32 discard_level = -1);
bool setSize(S32 width, S32 height, S32 ncomponents, S32 discard_level = -1);
void setComponents(S32 ncomponents) { mComponents = (S8)ncomponents ;}
void setAllowCompression(bool allow) { mAllowCompression = allow; }

View File

@ -1928,6 +1928,12 @@ bool LLTextureCache::writeToFastCache(S32 id, LLPointer<LLImageRaw> raw, S32 dis
{
//make a duplicate to keep the original raw image untouched.
raw = raw->duplicate();
if (raw->isBufferInvalid())
{
LL_WARNS() << "Invalid image duplicate buffer" << LL_ENDL;
return false;
}
raw->scale(w, h) ;
discardlevel += i ;