In the following code:
("GLRenderableObject.cpp")
("GLRenderableObject.h")Code :#include "GLRenderableObject.h" bool GLRenderableObject::wasMouseFuncRegistered = false; GLRenderableObject* GLRenderableObject::objects[256]; int GLRenderableObject::objectCount = 0; GLRenderableObject::GLRenderableObject() { if (!wasMouseFuncRegistered) { wasMouseFuncRegistered = true; objects[objectCount++] = this; [B]// Here I get an exception described below.[/B] glutMouseFunc(StaticMouseFunction); [i]// If comment the above, the same exc appears too[/i] glutMotionFunc(StaticMotionFunction); } } void GLRenderableObject::StaticMouseFunction(int button, int state, int x, int y) { for (int i = 0; i < objectCount; i++) objects[i]->OnMouseEvent(button, state, x, y); } void GLRenderableObject::StaticMotionFunction(int x, int y) { for (int i = 0; i < objectCount; i++) objects[i]->OnMotion(x, y); }
I get "Unhandled exception at 0x100085fa in BransleysFern.exe: 0xC0000005: Access violation reading location 0x000000b0." on a line marked above. I tried to convert a static function to a global one but nothing changed.Code :#pragma once #include "stdafx.h" class GLRenderableObject { private: static GLRenderableObject* objects[256]; static int objectCount; static bool wasMouseFuncRegistered; static void StaticMouseFunction(int button, int state, int x, int y); static void StaticMotionFunction(int x, int y); public: GLRenderableObject(); virtual void Render() abstract {} virtual void OnMouseEvent(int button, int state, int x, int y) {}; virtual void OnMotion(int x, int y) {}; };
Please help, I am a beginner.
I use OpenGL 3.1 + Visual Studio 2008 + C++ + glut.




