Skip to content

Commit ad3ab5a

Browse files
author
alfonse
committed
Issue #53: Delete shader objects properly.
1 parent 52fdc86 commit ad3ab5a

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Tut 01 Hello Triangle/tut1.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
#include <algorithm>
23
#include <string>
34
#include <vector>
45
#include <stdio.h>
@@ -61,6 +62,9 @@ GLuint CreateProgram(const std::vector<GLuint> &shaderList)
6162
delete[] strInfoLog;
6263
}
6364

65+
for(size_t iLoop = 0; iLoop < shaderList.size(); iLoop++)
66+
glDetachShader(program, shaderList[iLoop]);
67+
6468
return program;
6569
}
6670

@@ -92,6 +96,8 @@ void InitializeProgram()
9296
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, strFragmentShader));
9397

9498
theProgram = CreateProgram(shaderList);
99+
100+
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
95101
}
96102

97103
const float vertexPositions[] = {

framework/framework.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
#include <algorithm>
23
#include <string>
34
#include <vector>
45
#include <fstream>
@@ -49,6 +50,8 @@ namespace Framework
4950
fprintf(stderr, e.what());
5051
throw;
5152
}
53+
54+
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
5255
}
5356

5457
float DegToRad(float fAngDeg)

framework/framework.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Framework
1313
GLuint CreateShader(GLenum eShaderType,
1414
const std::string &strShaderFile, const std::string &strShaderName);
1515
GLuint LoadShader(GLenum eShaderType, const std::string &strShaderFilename);
16+
17+
//Will *delete* the shaders given.
1618
GLuint CreateProgram(const std::vector<GLuint> &shaderList);
1719

1820
//Will find a file with the given base filename, either in the local directory or the global one.

0 commit comments

Comments
 (0)