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 3 of 3

Thread: glDrawArrays causes segfault

  1. #1
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    2

    glDrawArrays causes segfault

    Help

    I just started learning openGL and whenever I call glDrawArrays my program segfaults. Since I'm working on a laptop with an nvidia GPU I made sure I run the program through optirun and that I've installed the proprietary drivers.

    I'm working in codeblocks and this is the output I get when I run the program:

    GLFW init succeeded
    vertex shader compilation succeeded
    fragment shader compilation succeeded
    Going to create program now
    Attaching shaders
    Linking program
    Program should work
    Initializing vertex buffers
    Generating vertex arrays
    Binding vertex array
    stuff should work
    Reshaped viewport
    Cleared stuff
    Used program
    stuff 1
    Segmentation fault

    Process returned 139 (0x8B) execution time : 0.139 s
    Press ENTER to continue.

    I'm not sure where I'm going wrong. Did I mess up the shaders? Or the creation of the openGL program? Or did I call glDrawArrays incorrectly?

    Any help would

  2. #2
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    2
    I've also posted the code online if that would help:

    /gXQTbDDC on pastebin

  3. #3
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    457
    One potential problem is that you're passing positionBufferObject by value to initializeVertexBuffers, but then you take the address of the passed argument and try to change the value. If your code compiles as-is, it would probably still compile if you were to call initializeVertexBuffers(42) even though that is more obviously wrong.

    Relevant bits of code:
    Code :
    int main(){
      GLuint positionBufferObject;
      ...
      initializeVertexBuffers(positionBufferObject);  //positionBufferObject unchanged, therefore still uninitialized
      ...
      while(glfwWindowShouldClose(newWindow) == 0)
      {
        ..
        display(positionBufferObject, ...);
    }
     
     
    void initializeVertexBuffers(GLuint positionBufferObject)
    {
      glGenBuffers(1, &positionBufferObject); 
      ...
    }

Posting Permissions

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