From 0fb584ad9208c37ec2ae67e4543996f90dbf0330 Mon Sep 17 00:00:00 2001 From: Timothy Zhang Date: Fri, 24 Oct 2014 18:31:00 +0800 Subject: [PATCH 1/3] release old program with the same key before adding glprogram --- cocos/renderer/CCGLProgramCache.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index b81f00975c..963a700af0 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; } From 80230258d67d55c4a44d263fb286801df3d2b3aa Mon Sep 17 00:00:00 2001 From: Timothy Zhang Date: Mon, 27 Oct 2014 09:59:47 +0800 Subject: [PATCH 2/3] replace tab with 4 spaces --- cocos/renderer/CCGLProgramCache.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index 963a700af0..2273e1f02e 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -432,13 +432,13 @@ GLProgram* GLProgramCache::getGLProgram(const std::string &key) void GLProgramCache::addGLProgram(GLProgram* program, const std::string &key) { - // release old one + // release old one auto prev = getProgram(key); - if( prev == program ) - return; + if( prev == program ) + return; - _programs.erase(key); - CC_SAFE_RELEASE_NULL(prev); + _programs.erase(key); + CC_SAFE_RELEASE_NULL(prev); if (program) program->retain(); From d42f8cac65eb6f0288790b5acca9390dd94963f9 Mon Sep 17 00:00:00 2001 From: Timothy Zhang Date: Mon, 27 Oct 2014 10:02:28 +0800 Subject: [PATCH 3/3] replace tab with 4 spaces --- cocos/renderer/CCGLProgramCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index 2273e1f02e..defb6080bb 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -433,9 +433,9 @@ GLProgram* GLProgramCache::getGLProgram(const std::string &key) void GLProgramCache::addGLProgram(GLProgram* program, const std::string &key) { // release old one - auto prev = getProgram(key); + auto prev = getProgram(key); if( prev == program ) - return; + return; _programs.erase(key); CC_SAFE_RELEASE_NULL(prev);