Skip to content
Snippets Groups Projects
Commit f43e46bc authored by Stinson Linden's avatar Stinson Linden
Browse files

MAINT-4009: Ensuring that the pick mask for the LLImageGL is always properly...

MAINT-4009: Ensuring that the pick mask for the LLImageGL is always properly freed during its cleanup method.
parent 37d62046
No related branches found
No related tags found
No related merge requests found
...@@ -390,9 +390,7 @@ LLImageGL::~LLImageGL() ...@@ -390,9 +390,7 @@ LLImageGL::~LLImageGL()
{ {
LLImageGL::cleanup(); LLImageGL::cleanup();
sImageList.erase(this); sImageList.erase(this);
disclaimMem((mPickMaskWidth * mPickMaskHeight + 7) / 8); freePickMask();
delete [] mPickMask;
mPickMask = NULL;
sCount--; sCount--;
} }
...@@ -461,6 +459,8 @@ void LLImageGL::cleanup() ...@@ -461,6 +459,8 @@ void LLImageGL::cleanup()
{ {
destroyGLTexture(); destroyGLTexture();
} }
freePickMask();
mSaveData = NULL; // deletes data mSaveData = NULL; // deletes data
} }
...@@ -504,10 +504,7 @@ void LLImageGL::setSize(S32 width, S32 height, S32 ncomponents, S32 discard_leve ...@@ -504,10 +504,7 @@ void LLImageGL::setSize(S32 width, S32 height, S32 ncomponents, S32 discard_leve
} }
// pickmask validity depends on old image size, delete it // pickmask validity depends on old image size, delete it
disclaimMem((mPickMaskWidth * mPickMaskHeight + 7) / 8); freePickMask();
delete [] mPickMask;
mPickMask = NULL;
mPickMaskWidth = mPickMaskHeight = 0;
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
...@@ -1885,6 +1882,37 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h) ...@@ -1885,6 +1882,37 @@ void LLImageGL::analyzeAlpha(const void* data_in, U32 w, U32 h)
} }
} }
//----------------------------------------------------------------------------
U32 LLImageGL::createPickMask(S32 pWidth, S32 pHeight)
{
U32 pick_width = pWidth/2 + 1;
U32 pick_height = pHeight/2 + 1;
U32 size = pick_width * pick_height;
size = (size + 7) / 8; // pixelcount-to-bits
mPickMask = new U8[size];
claimMem(size);
mPickMaskWidth = pick_width - 1;
mPickMaskHeight = pick_height - 1;
memset(mPickMask, 0, sizeof(U8) * size);
return size;
}
//----------------------------------------------------------------------------
void LLImageGL::freePickMask()
{
// pickmask validity depends on old image size, delete it
if (mPickMask != NULL)
{
disclaimMem((mPickMaskWidth * mPickMaskHeight + 7) / 8);
delete [] mPickMask;
}
mPickMask = NULL;
mPickMaskWidth = mPickMaskHeight = 0;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in)
{ {
...@@ -1893,10 +1921,7 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) ...@@ -1893,10 +1921,7 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in)
return ; return ;
} }
disclaimMem((mPickMaskWidth * mPickMaskHeight + 7) / 8); freePickMask();
delete [] mPickMask;
mPickMask = NULL;
mPickMaskWidth = mPickMaskHeight = 0;
if (mFormatType != GL_UNSIGNED_BYTE || if (mFormatType != GL_UNSIGNED_BYTE ||
mFormatPrimary != GL_RGBA) mFormatPrimary != GL_RGBA)
...@@ -1905,17 +1930,7 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) ...@@ -1905,17 +1930,7 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in)
return; return;
} }
U32 pick_width = width/2 + 1; U32 pickSize = createPickMask(width, height);
U32 pick_height = height/2 + 1;
U32 size = pick_width * pick_height;
size = (size + 7) / 8; // pixelcount-to-bits
mPickMask = new U8[size];
claimMem(size);
mPickMaskWidth = pick_width - 1;
mPickMaskHeight = pick_height - 1;
memset(mPickMask, 0, sizeof(U8) * size);
U32 pick_bit = 0; U32 pick_bit = 0;
...@@ -1929,7 +1944,7 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) ...@@ -1929,7 +1944,7 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in)
{ {
U32 pick_idx = pick_bit/8; U32 pick_idx = pick_bit/8;
U32 pick_offset = pick_bit%8; U32 pick_offset = pick_bit%8;
llassert(pick_idx < size); llassert(pick_idx < pickSize);
mPickMask[pick_idx] |= 1 << pick_offset; mPickMask[pick_idx] |= 1 << pick_offset;
} }
......
...@@ -186,6 +186,9 @@ class LLImageGL : public LLRefCount, public LLTrace::MemTrackable<LLImageGL> ...@@ -186,6 +186,9 @@ class LLImageGL : public LLRefCount, public LLTrace::MemTrackable<LLImageGL>
mutable F32 mLastBindTime; // last time this was bound, by discard level mutable F32 mLastBindTime; // last time this was bound, by discard level
private: private:
U32 createPickMask(S32 pWidth, S32 pHeight);
void freePickMask();
LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL
U8* mPickMask; //downsampled bitmap approximation of alpha channel. NULL if no alpha channel U8* mPickMask; //downsampled bitmap approximation of alpha channel. NULL if no alpha channel
U16 mPickMaskWidth; U16 mPickMaskWidth;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment