Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glGenBuffers() crashing with Segmentation fault. (C++/GLFW/GLEW)

So, in my project I am using a seperate class to create buffers called Buffer.cpp. Here is the constructor

#define GLEW_STATIC
#define GLEW_NO_GLU
#define GLFW_NO_GLU

#include "GL/glew.h"
#include "GL/glfw.h"

Buffer::Buffer(GLenum _type, const void *data, GLsizei _size, GLenum usage) :  type(_type), size(_size)
{
  ...

  //Generate Buffer
  glGenBuffers(1, &buffer);

  ...
}

And the definitions of the members:

GLuint buffer;
const GLsizei size; 
const GLenum type;
Buffer(GLenum, const void*, GLsizei, GLenum);

The problem is that when I try to generate a buffer using for example this command:

Buffer vBuffer(GL_ARRAY_BUFFER, vertexPositions, sizeof(vertexPositions), GL_STATIC_DRAW);

the program crashes at glGenBuffers() with termination status "-1073741819". I tried debugging the program and this is what I got:

Program received signal SIGSEGV, Segmentation fault.

My card supports OpenGL 1.5 so that's not the case.

It is also worth to note that I compiled a static glew library myself.

EDIT: I finally fixed the problem. The problem was that I was calling glewInit() before creating an OpenGL rendering context.

like image 605
Andreas Goulas Avatar asked Jun 29 '12 17:06

Andreas Goulas


1 Answers

So your problem was that you were creating OpenGL context after you called glewInit() - and thus glewInit() had no way to set up GL entry points properly.

In this case glewInit() probably did return error code. Are you verifying error codes from functions? It should return GLEW_OK.

like image 172
Mārtiņš Možeiko Avatar answered Sep 19 '22 13:09

Mārtiņš Možeiko