diff --git a/cocos/renderer/CCGLProgram.cpp b/cocos/renderer/CCGLProgram.cpp index cef6a240a6..01bea45748 100644 --- a/cocos/renderer/CCGLProgram.cpp +++ b/cocos/renderer/CCGLProgram.cpp @@ -161,7 +161,7 @@ GLProgram::~GLProgram() for (auto e : _hashForUniforms) { - free(e.second); + free(e.second.first); } _hashForUniforms.clear(); } @@ -665,17 +665,22 @@ bool GLProgram::updateUniformLocation(GLint location, const GLvoid* data, unsign { GLvoid* value = malloc(bytes); memcpy(value, data, bytes ); - _hashForUniforms.insert(std::make_pair(location, value)); + _hashForUniforms.insert(std::make_pair(location, std::make_pair(value, bytes))); } else { - if (memcmp(element->second, data, bytes) == 0) + if (memcmp(element->second.first, data, bytes) == 0) { updated = false; } else { - memcpy(element->second, data, bytes); + if (element->second.second < bytes){ + GLvoid* value = realloc(element->second.first, bytes); + memcpy(value, data, bytes ); + _hashForUniforms[location] = std::make_pair(value, bytes); + }else + memcpy(element->second.first, data, bytes); } } @@ -936,7 +941,7 @@ void GLProgram::reset() for (auto e: _hashForUniforms) { - free(e.second); + free(e.second.first); } _hashForUniforms.clear(); diff --git a/cocos/renderer/CCGLProgram.h b/cocos/renderer/CCGLProgram.h index 9566846f5b..72876262e3 100644 --- a/cocos/renderer/CCGLProgram.h +++ b/cocos/renderer/CCGLProgram.h @@ -360,7 +360,7 @@ protected: std::unordered_map _userUniforms; std::unordered_map _vertexAttribs; - std::unordered_map _hashForUniforms; + std::unordered_map> _hashForUniforms; //cached director pointer for calling Director* _director; };