gluErrorString depending segmentation fault

Hi, I’m learning OpenGL from a website. The program just draws a colored square and It works without modification. In CreateShader():

void CreateShaders()
{
    //
    GLenum ErrorCheckValue = glGetError();
    //
    //cout << gluErrorString(ErrorCheckValue) << '
';
    //
    VertexShaderId = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(VertexShaderId, 1, &VertexShader, NULL);
    glCompileShader(VertexShaderId);

    FragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(FragmentShaderId, 1, &FragmentShader, NULL);
    glCompileShader(FragmentShaderId);

    ProgramId = glCreateProgram();
      glAttachShader(ProgramId, VertexShaderId);
      glAttachShader(ProgramId, FragmentShaderId);
    glLinkProgram(ProgramId);
    glUseProgram(ProgramId);
    //This line.
    ErrorCheckValue = glGetError();
    //
    if (ErrorCheckValue != GL_NO_ERROR) {
        cout << "ERROR: Could not create the shaders:
" <<
                gluErrorString(ErrorCheckValue) << '
';
        exit(-1);
    }
}

I thought it’d be better, if I defined ErrorCheckValue under the comment “This line.” rather than calling glGetError() twice before and after creating the shaders. I removed The first line, but the output was:

ERROR: Could not create the shaders:
invalid enumerant
Segmentation fault (core dumped)

If I add the first cout to the program with defining ErrorCheckValue at the beginning of the function, the output’s, “invalid enumerant” but the program works fine.

Why didn’t it work, after the modification?

Sorry, I couldn’t post the whole program, because the forum denies the post.

As far as i know Invalid enumerat, means that you passed an invalid parameter to an OpenGL function. Do you check the error code after each operations ? The GL may be in an unconsistent state from before.

If you use SDL, call glGetError after SDL initialization until it comes up with GL_NO_ERROR. also check if you have enabled. I found this might be useful http://stackoverflow.com/questions/20822087/why-does-this-crash-when-using-opengl-core-profile

Im also a beginner but just trying to help :smiley:

Why did the program work when I checked for error before and after creating shaders, although the error exists anyway? I found I could attach the source as a .txt file.

Remove all this code and see if it runs. Basically remove the error check or just remove the exit function. if ti runs then opengl is retaining the error from somewhere. It is hard it is messy till you get used to it, but you have to bear with it. All of us went a way or another into these things.

  //This line.
  ErrorCheckValue = glGetError();
  //
  if (ErrorCheckValue != GL_NO_ERROR)
  {
    fprintf(
      stderr,
      "ERROR: Could not create the shaders: %s 
",
      gluErrorString(ErrorCheckValue)
    );

    exit(-1);
  }

Small tip. To me it works if i move on and come back again to a problem. I move on to the next chapters and usually on Sundays I look at these things after I party a bit on Friday and Saturday. That helps me. :o

[QUOTE=lummxx;1261896]Remove all this code and see if it runs. Basically remove the error check or just remove the exit function. if ti runs then opengl is retaining the error from somewhere. It is hard it is messy till you get used to it, but you have to bear with it. All of us went a way or another into these things.

  //This line.
  ErrorCheckValue = glGetError();
  //
  if (ErrorCheckValue != GL_NO_ERROR)
  {
    fprintf(
      stderr,
      "ERROR: Could not create the shaders: %s 
",
      gluErrorString(ErrorCheckValue)
    );

    exit(-1);
  }

Small tip. To me it works if i move on and come back again to a problem. I move on to the next chapters and usually on Sundays I look at these things after I party a bit on Friday and Saturday. That helps me. :o[/QUOTE]
Sorry for the late reply. :o:o
I removed all error checking then the program also worked well.
I removed error checking from the CreateShader() only, but the program didn’t work and got the same error, because error checking in CreateVBO() was at the end of the function like it was in CreateShader() at first. It seems that checking error at the begin and at the end of CreateShader() somehow prevented entering the exit(-1); block in all functions.