tests:Fix memory leak in MipmapTest

Update createRGBInitData() to use/return std::vector instead of raw ptr
w/ "new." This prevents potential for memory leaks.

Bug: angleproject:2958
Change-Id: I4b1bb4ee293e171f56d1221a562e607ff8eb0fb3
Reviewed-on: https://chromium-review.googlesource.com/c/1375229
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Tobin Ehlis <tobine@google.com>
This commit is contained in:
Tobin Ehlis 2018-12-12 16:23:30 -07:00 коммит произвёл Commit Bot
Родитель 91002266bd
Коммит bec398774e
1 изменённых файлов: 22 добавлений и 26 удалений

Просмотреть файл

@ -58,10 +58,10 @@ class MipmapTest : public BaseMipmapTest
mCubeProgram(0),
mTexture2D(0),
mTextureCube(0),
mLevelZeroBlueInitData(nullptr),
mLevelZeroWhiteInitData(nullptr),
mLevelOneGreenInitData(nullptr),
mLevelTwoRedInitData(nullptr),
mLevelZeroBlueInitData(),
mLevelZeroWhiteInitData(),
mLevelOneGreenInitData(),
mLevelTwoRedInitData(),
mOffscreenFramebuffer(0)
{
setWindowWidth(128);
@ -157,7 +157,7 @@ void main()
glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
TexImageCubeMapFaces(0, GL_RGB, getWindowWidth(), GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, getWindowWidth(), getWindowWidth(),
0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData);
0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData.data());
// Complete the texture cube without mipmaps to start with.
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -174,17 +174,12 @@ void main()
glDeleteTextures(1, &mTexture2D);
glDeleteTextures(1, &mTextureCube);
SafeDeleteArray(mLevelZeroBlueInitData);
SafeDeleteArray(mLevelZeroWhiteInitData);
SafeDeleteArray(mLevelOneGreenInitData);
SafeDeleteArray(mLevelTwoRedInitData);
ANGLETest::TearDown();
}
GLubyte *createRGBInitData(GLint width, GLint height, GLint r, GLint g, GLint b)
std::vector<GLubyte> createRGBInitData(GLint width, GLint height, GLint r, GLint g, GLint b)
{
GLubyte *data = new GLubyte[3 * width * height];
std::vector<GLubyte> data(3 * width * height);
for (int i = 0; i < width * height; i += 1)
{
@ -216,10 +211,10 @@ void main()
GLuint mTexture2D;
GLuint mTextureCube;
GLubyte *mLevelZeroBlueInitData;
GLubyte *mLevelZeroWhiteInitData;
GLubyte *mLevelOneGreenInitData;
GLubyte *mLevelTwoRedInitData;
std::vector<GLubyte> mLevelZeroBlueInitData;
std::vector<GLubyte> mLevelZeroWhiteInitData;
std::vector<GLubyte> mLevelOneGreenInitData;
std::vector<GLubyte> mLevelTwoRedInitData;
private:
GLuint mOffscreenFramebuffer;
@ -412,7 +407,7 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Pass in level zero init data.
glBindTexture(GL_TEXTURE_2D, mTexture2D);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
GL_UNSIGNED_BYTE, mLevelZeroBlueInitData);
GL_UNSIGNED_BYTE, mLevelZeroBlueInitData.data());
ASSERT_GL_NO_ERROR();
// Disable mips.
@ -442,7 +437,7 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Pass in level one init data.
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGB,
GL_UNSIGNED_BYTE, mLevelOneGreenInitData);
GL_UNSIGNED_BYTE, mLevelOneGreenInitData.data());
ASSERT_GL_NO_ERROR();
// Draw a full-sized quad, and check it's blue.
@ -468,7 +463,7 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Pass in level two init data.
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, getWindowWidth() / 4, getWindowHeight() / 4, 0, GL_RGB,
GL_UNSIGNED_BYTE, mLevelTwoRedInitData);
GL_UNSIGNED_BYTE, mLevelTwoRedInitData.data());
ASSERT_GL_NO_ERROR();
// Draw a full-sized quad, and check it's blue.
@ -496,7 +491,7 @@ TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData)
// Now reset level 0 to white, keeping mipmaps disabled. Then, render various sized quads. They
// should be white.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
GL_UNSIGNED_BYTE, mLevelZeroWhiteInitData);
GL_UNSIGNED_BYTE, mLevelZeroWhiteInitData.data());
ASSERT_GL_NO_ERROR();
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
@ -528,7 +523,7 @@ TEST_P(MipmapTest, GenerateMipmapFromInitDataThenRender)
// Pass in initial data so the texture is blue.
glBindTexture(GL_TEXTURE_2D, mTexture2D);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
GL_UNSIGNED_BYTE, mLevelZeroBlueInitData);
GL_UNSIGNED_BYTE, mLevelZeroBlueInitData.data());
// Then generate the mips.
glGenerateMipmap(GL_TEXTURE_2D);
@ -681,7 +676,8 @@ TEST_P(MipmapTest, DefineValidExtraLevelAndUseItLater)
{
glBindTexture(GL_TEXTURE_2D, mTexture2D);
GLubyte *levels[] = {mLevelZeroBlueInitData, mLevelOneGreenInitData, mLevelTwoRedInitData};
GLubyte *levels[] = {mLevelZeroBlueInitData.data(), mLevelOneGreenInitData.data(),
mLevelTwoRedInitData.data()};
int maxLevel = 1 + floor(log2(std::max(getWindowWidth(), getWindowHeight())));
@ -692,10 +688,10 @@ TEST_P(MipmapTest, DefineValidExtraLevelAndUseItLater)
}
// Define an extra level that won't be used for now
GLubyte *magentaExtraLevelData =
std::vector<GLubyte> magentaExtraLevelData =
createRGBInitData(getWindowWidth() * 2, getWindowHeight() * 2, 255, 0, 255);
glTexImage2D(GL_TEXTURE_2D, maxLevel, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE,
magentaExtraLevelData);
magentaExtraLevelData.data());
ASSERT_GL_NO_ERROR();
@ -719,11 +715,11 @@ TEST_P(MipmapTest, DefineValidExtraLevelAndUseItLater)
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
// Now redefine everything above level 8 to be a mipcomplete chain again.
GLubyte *levelDoubleSizeYellowInitData =
std::vector<GLubyte> levelDoubleSizeYellowInitData =
createRGBInitData(getWindowWidth() * 2, getWindowHeight() * 2, 255, 255, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth() * 2, getWindowHeight() * 2, 0, GL_RGB,
GL_UNSIGNED_BYTE, levelDoubleSizeYellowInitData); // 256
GL_UNSIGNED_BYTE, levelDoubleSizeYellowInitData.data()); // 256
for (int i = 0; i < maxLevel - 1; i++)
{