Get Access violation reading location 0x000000b0 with glutMouseFunc

0

I'm using glutMouseFunc(mouseFunction); as a callback however I keep getting the Access violation reading location 0x000000b0 at this line glutMouseFunc(mouseFunction);

I'm not using any of the glutInit functions because they interfere with the program and they are not essential anyways.

Does anyone know why I'm getting this error when at this callback?

Here is my initialize function:

   int Initialize()
   {
      /* Bunch of code here that is irrelevant to the problem.......*/
      glutMouseFunc(mouseFunction); // Error occurs here.
   }

And here is my mouseFunction:

    void mouseFunction(int button, int state, int x, int y){
      if(button==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) 
          {
               printf("Pressed middle mouse button!");
          }
      }

I've noticed one thing though, there error does not occur when I call the mouseFunction() as a normal function call in my Initialize method however once I try to use the mouseFunction with glutMouseFunc(mouseFunction), than the error happens so I believe this is more of an error with glutMouseFunc.

c++
opengl
glut
access-violation
asked on Stack Overflow Feb 17, 2014 by Morelka • edited Feb 17, 2014 by Morelka

2 Answers

3

I'm not using any of the glutInit functions because they interfere with the program and they are not essential anyways.

This is your problem. If you're going to use GLUT, use it correctly.

The glutInit() function is essential - part of what it does is initializing internal state within GLUT. As you've discovered, with this state not properly initialized, other parts of GLUT (such as mouse event handling!) may not work properly.

answered on Stack Overflow Feb 17, 2014 by duskwuff -inactive-
2

Given your comments to the other questions your problem is simply, that you call glutMouseFunc without a GLUT window. Trying to register GLUT event callbacks without proper initialization or without a GLUT window created will crash your program.

You also say "GLUT interferes" with your actual window. So why would you try to register a GLUT callback at all if you don't have a window that could actually receive the events for GLUT to dispatch?

You should use the mouse event handling of the window you've already got. And what are you using GLUT for then anyway? The whole purpose of GLUT is to create a window for you and do event management. If you don't use GLUT for that, then don't use GLUT at all.

If it's for the teapot, well, you can have that without GLUT as well.

answered on Stack Overflow Feb 18, 2014 by datenwolf

User contributions licensed under CC BY-SA 3.0