diff --git a/cocos/renderer/backend/opengl/ShaderModuleGL.cpp b/cocos/renderer/backend/opengl/ShaderModuleGL.cpp index 8067cc14e0..4c7e1abe0f 100644 --- a/cocos/renderer/backend/opengl/ShaderModuleGL.cpp +++ b/cocos/renderer/backend/opengl/ShaderModuleGL.cpp @@ -56,21 +56,23 @@ void ShaderModuleGL::compileShader(ShaderStage stage, const std::string &source) glGetShaderiv(_shader, GL_COMPILE_STATUS, &status); if (!status) { - cocos2d::log("cocos2d: ERROR: Failed to compile shader, detail: %s\n%s", getErrorLog(_shader), source.c_str()); + GLint logLength = 0; + glGetShaderiv(_shader, GL_INFO_LOG_LENGTH, &logLength); + + if (logLength > 1) { + cocos2d::Data errorLog{}; + glGetShaderInfoLog(_shader, logLength, nullptr, (char*) errorLog.resize(logLength)); + cocos2d::log("cocos2d: ERROR: Failed to compile shader, detail: %s\n%s", errorLog.getBytes(), source.c_str()); + } + else { + cocos2d::log("cocos2d: ERROR: Failed to compile shader without errors."); + } + deleteShader(); CCASSERT(false, "Shader compile failed!"); } } -char* ShaderModuleGL::getErrorLog(GLuint shader) const -{ - GLint logLength = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); - char* log = (char*)malloc(sizeof(char) * logLength); - glGetShaderInfoLog(shader, logLength, nullptr, log); - return log; -} - void ShaderModuleGL::deleteShader() { if (_shader) diff --git a/cocos/renderer/backend/opengl/ShaderModuleGL.h b/cocos/renderer/backend/opengl/ShaderModuleGL.h index 365468791c..2842ea232d 100644 --- a/cocos/renderer/backend/opengl/ShaderModuleGL.h +++ b/cocos/renderer/backend/opengl/ShaderModuleGL.h @@ -55,7 +55,6 @@ public: private: void compileShader(ShaderStage stage, const std::string& source); - char* getErrorLog(GLuint shader) const; void deleteShader(); GLuint _shader = 0;