Info log of a failed shader compile: 0��t What is wrong?

Hello GL guru!

This problem is such weird I’m sure it has a simple explanation.

This code:

https://github.com/Narann/mupen64plus-video-rice/blob/master/src/OGLCombiner.cpp#L134


GLint status;
pglGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE)
{
  printf("Compile shader failed:
");
  printf("Shader type: ");
  switch(shaderType)
  {
    case GL_VERTEX_SHADER :
      printf("Vertex
");
      break;
    case GL_FRAGMENT_SHADER :
      printf("Fragment
");
      break;
    default:
      printf("Unknown?
");
      break;
  }
  GLint param = 0;
  pglGetShaderiv(shader, GL_INFO_LOG_LENGTH, &param);

  GLsizei infoLogLength = (GLsizei) param;
  assert( infoLogLength >= 0 );

  GLchar infoLog[ infoLogLength ];
  pglGetShaderInfoLog(shader, infoLogLength, NULL, infoLog);

  printf("Info log:
%s
", infoLog);
  printf("GLSL code:
%s
", shaderSrc);

  pglDeleteShader(shader); OPENGL_CHECK_ERRORS
}

Return this:


Compile shader failed:
 Shader type: Fragment
 Info log:
 0��t

Can anyone explain me why I get this weird output message? What is wrong in my code? Is this driver related?

Notice I don’t have any problem with Desktop GL but it’s GL ES 2 which seems to be unable to compile.

A big thanks in advance! :slight_smile:

Note: The “OPENGL_CHECK_ERRORS” is empty.

This line seems rather dubious, in light of the fact that it’s not legal C++ (of any version).

GLchar infoLog[ infoLogLength ];

This is allowed under C99 or C11 rules, but from the rest of your code, you’re clearly compiling C++. That should have failed to compile.

The correct way to do this would be to use actual C++. For example, a std::string or a std::vector as a buffer, rather than a stack object.


std::vector<GLchar> errorLog(maxLength);
glGetShaderInfoLog(shader, maxLength, NULL, &errorLog[0]);

You might try actually checking for errors via glGetError().

E.g. if glCreateShader() fails, the functions which query its state will also fail, meaning that status, param, etc will be unchanged.

You might also want to initialise such variables so that the behaviour is sane even if the functions which are meant to set them fail.

Thanks Alfonse. I’m used to C but the code is a weird mix of C and C++. Thanks for pointing this. I will try using vector. :slight_smile:

What is weird is that this code work on desktop GL but not on GLES…

GClements: This is actually a macro. I was just saying this just in case anyone ask what the macro would do. I will try to activate it. :slight_smile: