Skip to content

Commit

Permalink
Merge pull request #2164 from Armada651/cache-fix
Browse files Browse the repository at this point in the history
ProgramShaderCache: Do plenty of error checking before writing shaders to the disk.
  • Loading branch information
degasus committed Mar 2, 2015
2 parents cd8c37b + 728081d commit cc5a2f3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,25 +473,33 @@ void ProgramShaderCache::Shutdown()
{
for (auto& entry : pshaders)
{
// Clear any prior error code
glGetError();

if (entry.second.in_cache)
{
continue;
}

GLint binary_size;
GLint link_status = GL_FALSE, delete_status = GL_TRUE, binary_size = 0;
glGetProgramiv(entry.second.shader.glprogid, GL_LINK_STATUS, &link_status);
glGetProgramiv(entry.second.shader.glprogid, GL_DELETE_STATUS, &delete_status);
glGetProgramiv(entry.second.shader.glprogid, GL_PROGRAM_BINARY_LENGTH, &binary_size);
if (!binary_size)
if (glGetError() != GL_NO_ERROR || link_status == GL_FALSE || delete_status == GL_TRUE || !binary_size)
{
continue;
}

u8 *data = new u8[binary_size+sizeof(GLenum)];
u8 *binary = data + sizeof(GLenum);
GLenum *prog_format = (GLenum*)data;
std::vector<u8> data(binary_size + sizeof(GLenum));
u8* binary = &data[sizeof(GLenum)];
GLenum* prog_format = (GLenum*)&data[0];
glGetProgramBinary(entry.second.shader.glprogid, binary_size, nullptr, prog_format, binary);
if (glGetError() != GL_NO_ERROR)
{
continue;
}

g_program_disk_cache.Append(entry.first, data, binary_size+sizeof(GLenum));
delete [] data;
g_program_disk_cache.Append(entry.first, &data[0], binary_size + sizeof(GLenum));
}

g_program_disk_cache.Sync();
Expand Down

0 comments on commit cc5a2f3

Please sign in to comment.