catching OpenGL errors...


I am trying to catch OpenGL errors.
So, I wrote a class that do this job:

class OGLlog : public Log
        OGLlog(char* fn);
         * @brief returns 1 if an OpenGL error occurred, 0 otherwise
        static int printError(char* fn)
    		GLenum glErr;
    		int retCode = 0;

    		glErr = glGetError();

			ofstream f(fn, ios::app);
			    tm now;
  				time_t t;
    			while (glErr != GL_NO_ERROR)
        			f<<now.tm_hour<<":"<<now.tm_min<<":"<<now.tm_sec<<"  /!\\ GL ERROR: "<<gluErrorString(glErr)<<endl;
        			retCode = 1;
        			glErr = glGetError();
   			else return -1;	

    		return retCode;

And now, this is the problem: When I call the printError function, My program stays stuck in the while loop that check if an ogl error remains!
I always have the opengl invalid operation error.

The more strange is that error occurs, even in the beginning of my program, where I did not call any opengl function!

I think that a fresh eye will see the big mistake I have made!

Thanks a lot.

If you by “at the beginning of the program” means before you set up the rendereing context, then that’s perfectly normal behaviour. You cannot call any OpenGL functions before a rendering context is propely configured. If you call glGetError before the rendering context is configured, it will return GL_INVALID_OPERATION if I remember correct, becuse it’s an invalid operation to call it without a rendering context.


As Bob said just check if an RC is current:
if (wglGetCurrentContex() != null) …


FYI: If you are trying to find OpenGL errors, this can be done automatically via tools like:

Ok thank you guys, I understand know. It is just like you said, I did not define the rendering context :slight_smile: I did know it is mandatory…

thank you sqrt[-1], for these links, it may be useful.