Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

c++ - GLSL shader compilation debugger results in a flood of the character x00 on the console

I am trying to debug my OpenGL shaders compilation but i'm having some strange output related to null characters I believe, my debugger console is flooded with a lot of x00 characters and I am trying to understand where does it come from and how to get rid of it. This is my function:

void DebugShader(GLuint shader) { //debug shader
    GLint isComp = 0;
    GLint maxLength;
    std::vector<GLchar> errorLog(maxLength); 
    std::string log; 
    glGetShaderiv(shader, GL_COMPILE_STATUS, &isComp); 
    if(isComp!=GL_TRUE) {
        glGetShaderiv(shader,GL_INFO_LOG_LENGTH,&maxLength);
        glGetShaderInfoLog(shader, maxLength, &maxLength,&errorLog[0]);
        std::cout << "Shader compilation Failed." << std::endl;
    }
    for (int i = 0; i<maxLength; i++){
        log.push_back(errorLog.at(i));
        std::cout << log;
    }
    if (isComp==GL_TRUE){
        std::cout << "Shader compilation successful." << std::endl;
        glDeleteShader(shader);
    }
}

This is the output I am getting:

"x00x00x00x00 ........ x00x00x00x00"

If I mess up the shader codes, just to check if the error output is working, I can find the error messages among those characters

question from:https://stackoverflow.com/questions/65891041/glsl-shader-compilation-debugger-results-in-a-flood-of-the-character-x00-on-the

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're using maxLength uninitialized to set the size of the vector errorLog. You need to resize errorLog after initializing maxLength.

The code should be more along the lines of (untested)...

void DebugShader(GLuint shader)
{
    GLint isComp = 0;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &isComp); 
    if(isComp!=GL_TRUE) {
        GLint maxLength;
        glGetShaderiv(shader,GL_INFO_LOG_LENGTH,&maxLength);
        std::vector<GLchar> errorLog(maxLength);
        glGetShaderInfoLog(shader, maxLength, &maxLength,&errorLog[0]);
        std::cout << "Shader compilation Failed." << std::endl;
    }
    .
    .
    .

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...