Exception 0xC0000005: Access Violation in the GLUT tutorial... Why ?

Hi everybody, I’m new to this forum.
I tried to compile the 1st source code given in the GLUT tutorial in VC++6, everything seems to be fine, the console and the GL window appear, but I then got the exception 0xC0000005: Access Violation…

Could anyone help ?? TIA.

Here’s the code:

#include <gl/glut.h>

void renderScene(void) {

void main(int argc, char **argv) {
glutInit(&argc, argv);
glutCreateWindow(“3D Tech- GLUT Tutorial”);

Sorry. I noticed after posting my previous message that this had been discussed in a thread before about exceptions… (read the answer from kilam)…

I too get an “unhandled exception in program.exe (GLUT32.DLL): 0xC0000005 Access Violation” from GLUT.

Unfortunatley, I could not find the soultion by “kilam”. It would have been better to place a link to the solution or gave the full description of where it is rather then only the name of someone who may have made a thousand posts.

This problem is caused by glutMouseFunc. I passed in an address to my function and it crashed. I passed NULL and it also crashed.

I am using the glut-3.7.6 binary for windows. I got it from http://www.xmission.com/~nate/glut.html .

Thanks in advance for the help.

What is the prototype of the function you passed to glutMouseFunc? It should be defined as

void somefuncname(int button, int state, int x, int y)//not necessarily those variable names


int main(int argc, char** argv)



Hope that helps. If not post some code and someone will probably be able to help you.

Here is my code.

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode)

glutMouseFunc( onMousePress); // Set callback function
glutMouseFunc( NULL); // Disable callback function


void onMousePress( int button, int state, int x, int y)

I am calling it correctly, I think there may be a problem with the “GLUT32.DLL” file or it is somehow not compatible with my program.

Now I didn’t place my entire real code because it is far too much. It is also possible that I may have setup an incompatible enviornment that causes glut functions not to work (that is other GL functions may produce an incompatable state).

I am also interested in knowing if glut has these kinds of compatability problems.


[This message has been edited by hkyProgrammer88 (edited 04-26-2003).]

It is impossible, to my knowledge, to mix GLUT and Win32/MFC app. Not in the way you are trying to do it. You can use win32 functions, etc, but glut has its own framework and it conflicts with the Win32/MFC framework. If you want to use GLUT, do so in a console type application.

int main(int argc, char** argv)
glutInit(&argc, argv);

glutCreateWindow(“A GLUT Window”):



Or, write a Win32 or MFC app but do not use GLUT. You can use gl or glu functions.

[This message has been edited by shinpaughp (edited 04-26-2003).]

Thanks! Its a good thing I put “winMain” instead of “main”.

Unfortunatley this is not ideal. I wanted to use glut to save me time, now it looks like I am going to have to manually code everything again.

If there is another library that already has tedious functions (like mouse routines) implemented I would like to know.

Thanks for the help,

Actually, glut will allow you to do it quickly. You could write an entire glut app in hours what would take days/weeks to do in Win32 with all messaging and stuff. And the code will be smaller also.

Or, is it that you have built the Win32 app and just want to add mouse handling functions. If so, go to http://msdn.microsoft.com and look up WM_MOUSE_MOVE, WM_LBUTTON_DOWN, etc. Should be just as easy to handle.

Thats right. In fact, my core custom library is based on Win32/MFC so it is not easy to switch.

In any event, I will both try to reprogram the library and add the utilities in another way.

Thanks for the help, I understand completely now.