Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 15

Thread: Access Violation GLEW/GLFW3

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14

    Access Violation GLEW/GLFW3

    Hello,

    I have the issue when following this tutorial..

    However when I do this:

    Code :
    unsigned int vbo = 0;
    glGenBuffers (1, &vbo);

    I get this:

    Code :
    Unhandled exception at 0x777ABDA1: 0xC0000005: Access violation executing location 0x00000000.

    And I have initiated glfw and glew..

    Any Suggestions?

    Many Thanks

    DoctorZeus

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    788
    Most likely glGenBuffers is not a valid function pointer, so the call fails. Possibly glew is not correctly initialized/encounters an error while initializing (do you set glewExperimental=TRUE before glewInit?) or your context creation does not work correctly.
    You'll have to post your code where you create the OpenGL context and initialize glew to say anything more specific.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by carsten neumann View Post
    Most likely glGenBuffers is not a valid function pointer, so the call fails. Possibly glew is not correctly initialized/encounters an error while initializing (do you set glewExperimental=TRUE before glewInit?) or your context creation does not work correctly.
    You'll have to post your code where you create the OpenGL context and initialize glew to say anything more specific.
    Thanks for the reply,

    Yes I have set glewExperimental to true before it is init..

    Here is my code to init and create a window:
    Code :
    bool CreateGraphicsWindow(unsigned int WindowSizeX, unsigned int WindowSizeY, char* WindowName = (char*)"MAIN WINDOW", bool fullScreen = false)
        {
    	glewExperimental=true;
            if (!glewInit() || !glfwInit())
            {
                TerminateNReturn((char*)"CANNOT INITALIZE GRAPHICS!");
                return false;
            }
     
            if (fullScreen)
                GraphicsWindow = glfwCreateWindow(WindowSizeX, WindowSizeY, WindowName, glfwGetPrimaryMonitor(), NULL);
            else
                GraphicsWindow = glfwCreateWindow(WindowSizeX, WindowSizeY, WindowName, NULL, NULL);
            if (!GraphicsWindow)
            {
                TerminateNReturn((char*)"CANNOT CREATE WINDOW");
                return false;
            }
     
            glfwMakeContextCurrent(GraphicsWindow);
     
            return true;
        }

    Many Thanks

    DoctorZeus

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    You have to initialize GLFW first. You need an active OpenGL context before you can load OpenGL functions or make any OpenGL calls.

    This means you need to initialize GLFW, set up your window properties, and then create a window. All before touching GLEW or anything in OpenGL.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by Alfonse Reinheart View Post
    You have to initialize GLFW first. You need an active OpenGL context before you can load OpenGL functions or make any OpenGL calls.

    This means you need to initialize GLFW, set up your window properties, and then create a window. All before touching GLEW or anything in OpenGL.
    Correct me if I am wrong (Noob alert with opengl here) but isnt glfw inialized with glfwinit() and the window created with glfwCreateGraphicsWindow?

    I can render basic shapes by specifying the coords using glBegin and glEnd and these render fine when entered in manually (I can render basic cubes and etc, etc..

    Thanks

    DoctorZeus

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Correct me if I am wrong (Noob alert with opengl here) but isnt glfw inialized with glfwinit() and the window created with glfwCreateGraphicsWindow?
    Yes. And your call to "glewInit" comes before all of that. You have to initialize GLEW after creating the window, not before.

    I can render basic shapes by specifying the coords using glBegin and glEnd and these render fine when entered in manually (I can render basic cubes and etc, etc..
    That's because GLEW's macros pipe the GL 1.1 stuff through non-GLEW functions. Any functions from later GL versions will fail because GLEW has not been properly initialized yet.

  7. #7
    Newbie Newbie
    Join Date
    Dec 2013
    Posts
    1
    Hi Alfonse Reinheart...could you help me please! I've been stuck on this for hours...I'm having the same access violation when calling glGenbuffers. I made sure I followed these steps exactly (initializing glfw, setting window properties, then creating the window before glew calls) and what I've done is in line with everything else I've found online. I'm rather new to openGL so I'm really lost as to what could be going wrong.

    This is how I've written it:
    glfwInit();
    glewExperimental = GL_TRUE;
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(1200, 800, "Game", nullptr, nullptr); // Windowed

    glewInit();


    typedef void(*GENBUFFERS) (GLsizei, GLuint*);

    // Load address of function and assign it to a function pointer
    GENBUFFERS glGenBuffers = (GENBUFFERS)wglGetProcAddress("glGenBuffers");

    // Call function as normal
    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);

    printf("%u\n", vertexBuffer);

    Any help would be greatly appreciated!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •