View Full Version : glDrawArrays causes segfault

08-10-2014, 06:40 AM

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

08-10-2014, 06:42 AM
I've also posted the code online if that would help:

/gXQTbDDC on pastebin

Dan Bartlett
08-10-2014, 12:09 PM
One potential problem is that you're passing positionBufferObject by value (http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/PARAMS.html#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:

int main(){
GLuint positionBufferObject;
initializeVertexBuffers(positionBufferObject); //positionBufferObject unchanged, therefore still uninitialized
while(glfwWindowShouldClose(newWindow) == 0)
display(positionBufferObject, ...);

void initializeVertexBuffers(GLuint positionBufferObject)
glGenBuffers(1, &positionBufferObject);