ktb92677
Posts: 28
Joined: Fri Sep 20, 2013 10:29 pm

glGetShaderInfoLog is empty

Wed Aug 14, 2019 12:14 am

Hi all, I have been looking for a while for a solution to this problem but I cannot find it. The code base I am working on currently is nearly identical to the code base here: https://github.com/vurtun/nuklear/tree/ ... _opengles2.

What I would like to do is within the same instance of the program fully initialize and delete an SDL+GLES instance twice within the run time of the same program. I have adapted the code base posted above to simply call the contents of main() twice with a slight pause in between. However on the second run the following assert fails:

Code: Select all

glShaderSource(dev->vert_shdr, 1, &vertex_shader, 0);
    glShaderSource(dev->frag_shdr, 1, &fragment_shader, 0);
    glCompileShader(dev->vert_shdr);
    glCompileShader(dev->frag_shdr);
    glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
    assert(status == GL_TRUE);
This can be found on line 116 in the file nuklear_sdl_gles2.h. I used the following code to print the error:

Code: Select all

if (status != GL_TRUE) {
                GLint maxLength;
        glGetShaderiv(dev->vert_shdr, GL_INFO_LOG_LENGTH, &maxLength);

                GLchar infoLog[maxLength];

                memset(&infoLog, 0, maxLength);

                glGetShaderInfoLog(dev->vert_shdr, maxLength, &maxLength, infoLog);

                printf("error: %s\n", infoLog);
        }
maxLength is zero after glGetShaderiv returns. Also if I manually set maxLength to a larger number glGetShaderInfoLog doesn't even touch infoLog. It leaves it completely empty. Any help would be greatly appreciated

User avatar
PeterO
Posts: 5138
Joined: Sun Jul 22, 2012 4:14 pm

Re: glGetShaderInfoLog is empty

Wed Aug 14, 2019 7:54 am

My equivalent code is below. Only difference I can see is that I pass "NULL" for the length pointer when calling glGetShaderInfoLog

Code: Select all

    glCompileShader(shaderId);

    glGetShaderiv(shaderId,GL_COMPILE_STATUS,&compiledOk );

    if(compiledOk == GL_FALSE)
    {
        GLint logLength;

        glGetShaderiv(shaderId,GL_INFO_LOG_LENGTH,&logLength);
      
        if(logLength > 1)
        {
            char *logText;
            logText = malloc((size_t)logLength);

            glGetShaderInfoLog(shaderId,logLength,NULL,logText);
            fprintf(stderr,"Shader from %s didn't compile!\n%s\n",filename,logText);            
         
            free(logText);
      }

      glDeleteShader(shaderId);
      return 0;
    }
    return(shaderId);
}
I get error text like this from it ..

Code: Select all

shader from WGbuttonVShader.c didn't compile!
0:2(1): preprocessor error: #version must appear on the first line

Vertex Shader (WGbuttonVShader.c) id=0
e=0x0
Fragment Shader (WGbuttonFShader.c) id=2
e=0x0
Program (WGProg) id=3
Linking WGProg failed: error: program lacks a vertex shader
The lines "e=0x0" are from code like this that I include after every gl call for use while developing to catch errors. When it works I disable them,
and finally remove them.

Code: Select all

#if ERRORCHEKING
        e = glGetError();
        printf("e=0x%x\n",e);
#endif
Are you sure there have not been any other errors before this code is executed ?
When did your code last check for errors by calling glGetError() ?

HTH
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

ktb92677
Posts: 28
Joined: Fri Sep 20, 2013 10:29 pm

Re: glGetShaderInfoLog is empty

Wed Aug 14, 2019 6:51 pm

PeterO wrote:
Wed Aug 14, 2019 7:54 am
My equivalent code is below. Only difference I can see is that I pass "NULL" for the length pointer when calling glGetShaderInfoLog

Code: Select all

    glCompileShader(shaderId);

    glGetShaderiv(shaderId,GL_COMPILE_STATUS,&compiledOk );

    if(compiledOk == GL_FALSE)
    {
        GLint logLength;

        glGetShaderiv(shaderId,GL_INFO_LOG_LENGTH,&logLength);
      
        if(logLength > 1)
        {
            char *logText;
            logText = malloc((size_t)logLength);

            glGetShaderInfoLog(shaderId,logLength,NULL,logText);
            fprintf(stderr,"Shader from %s didn't compile!\n%s\n",filename,logText);            
         
            free(logText);
      }

      glDeleteShader(shaderId);
      return 0;
    }
    return(shaderId);
}
I get error text like this from it ..

Code: Select all

shader from WGbuttonVShader.c didn't compile!
0:2(1): preprocessor error: #version must appear on the first line

Vertex Shader (WGbuttonVShader.c) id=0
e=0x0
Fragment Shader (WGbuttonFShader.c) id=2
e=0x0
Program (WGProg) id=3
Linking WGProg failed: error: program lacks a vertex shader
The lines "e=0x0" are from code like this that I include after every gl call for use while developing to catch errors. When it works I disable them,
and finally remove them.

Code: Select all

#if ERRORCHEKING
        e = glGetError();
        printf("e=0x%x\n",e);
#endif
Are you sure there have not been any other errors before this code is executed ?
When did your code last check for errors by calling glGetError() ?

HTH
PeterO
I have your code pasted verbatim and glGetShaderiv returns 0. I have no idea how the status could be set to failed but gles decides to give no output. How is that possible?

User avatar
PeterO
Posts: 5138
Joined: Sun Jul 22, 2012 4:14 pm

Re: glGetShaderInfoLog is empty

Wed Aug 14, 2019 7:01 pm

What is in the vertex and fragment shader files you are compiling ?

Are you sure there is any source code on the second run ? It's not getting deleted after the first time is it ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

ktb92677
Posts: 28
Joined: Fri Sep 20, 2013 10:29 pm

Re: glGetShaderInfoLog is empty

Wed Aug 14, 2019 7:16 pm

PeterO wrote:
Wed Aug 14, 2019 7:01 pm
What is in the vertex and fragment shader files you are compiling ?

Are you sure there is any source code on the second run ? It's not getting deleted after the first time is it ?

PeterO
Here is the exact source code I am using: https://github.com/vurtun/nuklear/blob/ ... dl_gles2.h.

It doesn't seem like I delete the shader files... seems to be defined in line actually. Take a look at the function nk_sdl_device_create() for exactly what I do.

ktb92677
Posts: 28
Joined: Fri Sep 20, 2013 10:29 pm

Re: glGetShaderInfoLog is empty

Wed Aug 14, 2019 7:43 pm

PeterO wrote:
Wed Aug 14, 2019 7:01 pm
What is in the vertex and fragment shader files you are compiling ?

Are you sure there is any source code on the second run ? It's not getting deleted after the first time is it ?

PeterO
Okay minor update. I tried outputting glGetString(GL_VERSION) and I noticed on the second run that it outputted (NULL). Which means I didn't even have a valid gl context to begin with on the second run, that's why there was no output from glGetShaderInfoLog. I traced it back to the following issue: SDL_CreateWindow() returns NULL the second time I call the function. The error is as follows: "Could not initialize OpenGL / GLES library". This is probably an issue with how I clean up SDL so I'll create a new issue in the appropriate place.

User avatar
PeterO
Posts: 5138
Joined: Sun Jul 22, 2012 4:14 pm

Re: glGetShaderInfoLog is empty

Wed Aug 14, 2019 7:58 pm

Ok, that makes sense. You could perhaps add some more checks on return values etc. then you'll catch these sorts of problems earlier on. As I said before I find frequent calls to glGetError() while still developing code can save a lot of time trying to hunt down a failed call that only shows up later in the execution flow.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “OpenGLES”