Merge pull request #8921 from TimothyZhang/fix-program-cache-add

release old program with the same key before adding glprogram
This commit is contained in:
minggo 2014-10-27 11:22:00 +08:00
commit f1ac0df761
1 changed files with 9 additions and 2 deletions

View File

@ -432,9 +432,16 @@ GLProgram* GLProgramCache::getGLProgram(const std::string &key)
void GLProgramCache::addGLProgram(GLProgram* program, const std::string &key)
{
// release old one
auto prev = getProgram(key);
if( prev == program )
return;
_programs.erase(key);
CC_SAFE_RELEASE_NULL(prev);
if (program)
program->retain();
program->retain();
_programs[key] = program;
}