PDA

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



Alexouin
11-24-2000, 05:15 PM
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>
#include<gl/gl.h>

void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glFlush();
}

void main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("3D Tech- GLUT Tutorial");
glutDisplayFunc(renderScene);
glutMainLoop();
}

Alexouin
11-24-2000, 05:35 PM
Sorry. I noticed after posting my previous message that this had been discussed in a thread before about exceptions... (read the answer from kilam)...

hkyProgrammer88
04-26-2003, 06:36 PM
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.

shinpaughp
04-26-2003, 07:05 PM
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)
{
...
glutMouseFunc(somefuncname);
...
}



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

hkyProgrammer88
04-26-2003, 08:49 PM
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.

Thanks

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

shinpaughp
04-26-2003, 09:08 PM
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);
glutInitDisplayMode(...);
....
glutCreateWindow("A GLUT Window"):
...
glutDisplayFunc(display);
...
glutMainLoop();
}

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).]

hkyProgrammer88
04-26-2003, 09:14 PM
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,

shinpaughp
04-26-2003, 09:30 PM
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.

hkyProgrammer88
04-26-2003, 09:35 PM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif