diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index b81f00975c..defb6080bb 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -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; }