Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [C++] Memory violation with glGenBuffers

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    20

    [C++] Memory violation with glGenBuffers

    Hello,

    I'm using OpenGL with C++ through glew and freeglut. I also do successfully load the necessary OpenGL-extentions.
    I get an memory violation error
    Code :
    Unhandled exception at 0x74DBC9F5 in MyProgram.exe: 0xC0000005: Access violation executing location 0x00000000.
    when trying to call this:
    Code :
    glGenBuffers(1, &vboHandle);
    VboHandle is a GLuint member of my Vao-class. I think the problem is that it's a GLuint and not a GLuint* but why?

    Thanks!
    Last edited by elfeck; 08-19-2013 at 03:43 PM.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    716
    To me this sounds more like GLEW is not correctly initialized and therefore glGenBuffers is not a valid function pointer, did you read this wiki page, in particular the part about using glewExperimental? Are you initializing GLEW after creating an OpenGL context? - it needs one to obtain the function pointers.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    20
    glewInit() ist returning GLEW_OK ... so I think that's not the problem.

    EDIT: I think I found the problem: I statically initalized the object calling glGenBuffers. At this point the OpenGL isn't initialized context yet.
    EDIT 2: Got the program up and running. Thanks anyway!
    Last edited by elfeck; 08-19-2013 at 04:23 PM.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    20
    Okay nothing is fine

    I get memory violations at the more recent OpenGL functions starting at glDrawElements. glslDevil crashes the program as soon as it calls glGenVertexArray. Strangly some functions seem to work: I can compile shaders and get errorlogs. Despite glslDevil crashing vbo,ibo and vao handles get set.
    But the fact remains that glewInit() returns GLEW_OK. glewExperimental is set to true. Can I specifically check wheather the modern OpenGL function pointers are loaded?

    Thanks!
    Last edited by elfeck; 08-20-2013 at 11:03 AM.

  5. #5
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by elfeck View Post
    I get memory violations at the more recent OpenGL functions starting at glDrawElements.
    There's nothing recent about glDrawElements(); that was introduced in OpenGL 1.1.

    Quote Originally Posted by elfeck View Post
    Can I specifically check wheather the modern OpenGL function pointers are loaded?
    Just treat the pointers as boolean values, e.g. "if (glGenVertexArray) ....".

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    20
    Function Pointer are loaded.
    It crashes with
    Code :
    Unhandled exception at 0x5936FD84 (ig7icd32.dll) in CPHemeral.exe: 0xC0000005: Access violation reading location 0x00000000.
    I'm at a loss here.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,180
    If you're loading GLEW correctly but you still get memory violations at glDrawElements a possible cause might be that you have a vertex attrib array enabled but no vertex attrib pointer set for it. Possibly the old GL_INDEX_ARRAY common mistake, even?

    Either way, I'd definitely recommend running your program under a good debugger which can help you determine where the violations are occurring and what might be causing them.

  8. #8
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    20
    Here is the interception log:
    Code :
    glViewport(0,0,480,320)
    glClearColor(0.000000,0.000000,0.000000,1.000000)
    glClear(GL_COLOR_BUFFER_BIT)
    glGenVertexArrays(1,03E92FE8)
    glBindVertexArray(1)
    glGenBuffers(1,03E92FEC)
    glBindBuffer(GL_ARRAY_BUFFER,1)
    glEnableVertexAttribArray(0)
    glVertexAttribPointer(0,4,GL_FLOAT,false,0,00000000)
    glDisableVertexAttribArray(0)
    glGenBuffers(1,03E92FF0)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,2)
    glBindVertexArray(0)
    glBindBuffer(GL_ARRAY_BUFFER,0)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0)
    glBindVertexArray(1)
    glCreateShader(GL_VERTEX_SHADER)=1 
    glShaderSource(1,1,0030F408,00000000)
    glCompileShader(1)
    glGetShaderiv(1,GL_COMPILE_STATUS,0030F3DC)
    glGetShaderiv(1,GL_INFO_LOG_LENGTH,0030F3D0)
    glGetShaderInfoLog(1,12,00000000,03D6F800)
    glCreateShader(GL_FRAGMENT_SHADER)=2 
    glShaderSource(2,1,0030F3FC,00000000)
    glCompileShader(2)
    glGetShaderiv(2,GL_COMPILE_STATUS,0030F3DC)
    glGetShaderiv(2,GL_INFO_LOG_LENGTH,0030F3D0)
    glGetShaderInfoLog(2,12,00000000,03D6F840)
    glCreateProgram()=3 
    glAttachShader(3,1)
    glAttachShader(3,2)
    glBindAttribLocation(3,0,"position")
    glLinkProgram(3)
    glGetProgramiv(3,GL_LINK_STATUS,0030F3F8)
    glGetProgramiv(3,GL_INFO_LOG_LENGTH,0030F3EC)
    glGetProgramInfoLog(3,12,00000000,03D6F900)
    glValidateProgram(3)
    glBindBuffer(GL_ARRAY_BUFFER,1)
    glBufferData(GL_ARRAY_BUFFER,48,0307D6D8,GL_STATIC_DRAW)
    glBindBuffer(GL_ARRAY_BUFFER,0)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,2)
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,6,0055C040,GL_STATIC_DRAW)
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0)
    glUseProgram(3)
    glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_SHORT,00000000) GLSL=3 
    ----->glClearColor(0.000000,0.000000,0.000000,1.000000)
    ----->glClear(GL_COLOR_BUFFER_BIT)
    ----->glBindVertexArray(1)
    ----->glUseProgram(3)
    ----->glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_SHORT,00000000)
    Is something wrong with that? If not I'll give you the code I'm using to setup and draw.

  9. #9
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    32
    I had a glGenBuffers access violation and it took me days to figure out that my whole issue was I needed to call glewInit() after I created the window. I'm using sdl to handle windows for me since it's easy and has everything I need but it should be the same regardless of what lib you use to create the window.

    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_SetVideoMode(640,480,32,SDL_OPENGL);
    glewInit();

  10. #10
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    20
    Thats not the problem. Using freeGlut and calling glewInit after the contex and window are created.

Posting Permissions

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