Access violation. when using GLEW and GLFW
Asked Answered
V

3

5

I am sure that everything is linked correcly. I initially was using glload and glfw from the Unofficial GLSDK but then I decided to do away with glload which meant that I had to use glew in order to get at the modern headers.

#include <GL/glew.h>
#include <GL/glfw.h>

I have included glew before glfw as per the instructions.

During run time the OpenGL window opens

//(relevant code)
if(!glewInit()) {return -1; }
if(!glfwInit()) {return -1; }
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// also tried glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);

if(!glfwOpenWindow(1024, 768, 8, 8, 8, 8, 24, 8, GLFW_WINDOW)){
    glfwTerminate();
    return -1;
}

glfwSetWindowTitle("OpenGL 3.2");

//init method
glGenVertexArrays(1, &vao);  //<<  Access violation here.

Any ideas what my problem is here?

I have looked at. "Access violation using VBO with glew" But it was no help.

Vinegarroon answered 19/12, 2012 at 0:38 Comment(0)
K
8

glewInit is to be called after a OpenGL context has been created and bound to the current thread, i.e. after glfwOpenWindow in your case.

Kovacs answered 19/12, 2012 at 1:32 Comment(1)
Thank you I moved that like you said. if(!glewInit()) {return -1; } was incorrect to I need to check the value it returns. as its not a boolVinegarroon
O
3

A little late, but figured I'd pipe in anyways.

As mentioned by datenwolf, in your relevant code posted the glewInit() should return an error due to it's positioning.

The other potential issue you could be encountering is described on http://www.opengl.org/wiki/OpenGL_Loading_Library under the GLEW section.

copy-paste from above:

GLEW has a problem with core contexts. It calls glGetString(GL_EXTENSIONS)​, which causes GL_INVALID_ENUM​ on GL 3.2+ core context as soon as glewInit()​ is called.

Solution for GLEW (also provided by above link) is to enable 'EXPERIMENTAL' support. Ex:

glewExperimental = GL_TRUE;
GLenum err = glewInit();
if( err != GLEW_OK )
{
    printf("GlewInit error");
    exit(1);
}
Osmund answered 1/11, 2013 at 5:30 Comment(0)
P
2

Also late but for anyone still looking

glewExperimental = GL_TRUE;

Before initializing the context was got rid of the access violation error, but instead made the program exit with a GL_INVALID_ENUM error. With GLFW, I had to additionally comment out the window hints:

//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);

The programs then started compiling!

Parenthesize answered 5/10, 2015 at 0:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.