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 17

Thread: glDrawArrays() Seg Fault

  1. #1
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    18

    glDrawArrays() Seg Fault

    right after I called glDrawArrays() I got:

    ***** FATAL EXCEPTION RECEIVED *******
    "
    ***** Vectored Exception Handler: Received fatal exception EXCEPTION_ACCESS_VIOLATION PID: 1048

    ******* STACKDUMP *******
    stack dump [0]
    stack dump [1]
    stack dump [2]
    stack dump [3]
    stack dump [4]
    stack dump [5]
    stack dump [6]
    stack dump [7]

    Exiting after fatal event (FATAL_EXCEPTION). Fatal type: EXCEPTION_ACCESS_VIOLATION
    Log content flushed flushed sucessfully to sink


    I was trying to run a test, which calls a bunch of gl funtions, I wrote a wgl class which helps to create the window and context.

    The test did not use OVB, it used glVertexAttribPointer.

    I have read a lot of people are using OVB with glDrawArrays, but Im not using that, so how can I make glDrawArrays() work?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,748
    The most common cause of a seg fault after glDraw* is that you have a vertex attrib array enabled but no vertex attrib pointer set for it.

    Help us to help you: you say "a bunch of GL functions" but you're not showing any code. You're making it very difficult for us to troubleshoot what might be happening, or provide any useful advice.

  3. #3
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    18
    I have created a window and glClearColor which works fine.
    Then I called:

    wglMakeCurrent

    glBindFramebuffer(GL_FRAMEBUFFER, 0)

    glViewPort(0, 0, window_width, window_height)

    glUseProgram(17) //

    glVertexAttribPointer(0, 2, DATA_FORMAT_FLOAT32, false, 2 * sizeof(pos[0]), data) //data is a void * but it was a float[8] in the
    function that calls glVertex*

    //I have glEnableVertexAttribArray() in my createProgram.

    glUniform4fv()

    glDisable(GL_BLEND)

    //until this point glGetError() returns 0

    glDrawArrays(GL_TRIANGLE_STRIP, 0 , 4) // the error shows when executing this line
    Last edited by whiack; 05-30-2016 at 10:10 AM.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2016
    Posts
    25
    Quote Originally Posted by whiack View Post
    glUseProgram(17)
    Why have you hardcoded 17? This should be the value returned by createProgram.

  5. #5
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    18
    17 is a program id returned by createProgram, I have stored it in a variable.

  6. #6
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    18
    Another thing I need to mention is that the program works fine in Linux, I'n converting it to windows. Then there is a seg fault. I don't know if there is an extra step that i should do in windows? For example, several days ago, I found out that I need glFlush() after glClearColor(), otherwise the glClearColor() don't work.

    Im using mingGW, converting glx and egl in project to wgl

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,594
    Quote Originally Posted by whiack View Post
    For example, several days ago, I found out that I need glFlush() after glClearColor(), otherwise the glClearColor() don't work.
    glFlush() is almost never needed. In situations where it makes a difference, you're more likely to need glFinish(). glFlush() forces pending commands to be executed at some point in the future; glFinish() waits until they have finished executing.

    It's fairly clear that there's a problem with your code which is manifesting itself in non-obvious ways. Memory corruption often has such symptoms, but there are other possibilities.

    I suggest looking at an existing cross-platform toolkit such as GLUT or GLFW for hints on using the Windows API.

  8. #8
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    18
    I tired to load glFinish() but I cannot load it with wglGetProcAddress nor GetProcAddress(opengl32,procName). Where can I get the glFinish()?

  9. #9
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    18
    Maybe this line is important :

    Program received signal SIGSEGV, Segmentation fault.
    0x0000000069ebad39 in nvoglv64!DrvPresentBuffers () from /cygdrive/c/windows/system32/nvoglv64.DLL

    The error shows that it's nvoglv64.DLL. I thought it was not an error for the program?

  10. #10
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    453
    as it has been said before, "access voilation" errors occur often when your vertexarray isnt set up correctly
    show us the full code of how you've build your vertexarray

    Code :
    glVertexAttribPointer(0, 2, DATA_FORMAT_FLOAT32, false, 2 * sizeof(pos[0]), data);

    have you bound a GL_ARRAY_BUFFER right before that line ??

    what is "DATA_FORMAT_FLOAT32" ??
    the type must be one of those:
    Code :
    GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,
    GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FIXED,
    GL_HALF_FLOAT, GL_FLOAT, or GL_DOUBLE

Tags for this Thread

Posting Permissions

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