poetryofruins poetryofruins - 1 month ago 9
C++ Question

Segfault on glNamedBufferStorage

I am currently reading the OpenGL Super Bible 7th edition. Based on that, I wrote some simple code like this:

void startup() {
static const float data[] = {
0.25f, -0.25f, 0.5f, 1.0f,
-0.25f, -0.25f, 0.5f, 1.0f,
0.25f, 0.25f, 0.5f, 1.0f,
};


glGenVertexArrays(1, &m_VAO);
glBindVertexArray(m_VAO);

glGenBuffers(1, &m_VBO);
glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
printf("Size of data[]: %lu bytes\n", sizeof(data));
glNamedBufferStorage(m_VBO, sizeof(data), data, GL_DYNAMIC_STORAGE_BIT);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(0);

}


This is a method of a class that is run before the main rendering loop.

The problem is that this code generates a segfault at
glNamedBufferStorage
.

I tried debugging it with gdb - and learned only where the segfault occurs, not why. I tried to understand if there is a problem with
data
's size (hence the
printf sizeof
). But it seems to be ok. I also tried to use different flags - also to no avail.

I also did a
grep -R
on the accompanying source code, but found no usage examples.

System: Ubuntu, clang++

Answer

Check your OpenGL version with

printf("OpenGL version (%s): \n", glGetString(GL_VERSION));

glNamedBufferStorage supported only on OpenGL 4.5

Comments