DSA: Segmentation fault when setting attribute pointers.

Hi. I’m trying to set vertex attribute pointers using the DSA technique. As a test I’m trying to substitute something that already works in a test program. The following two lines (including relevant function) worked in my program:

void setVertexAttribPointer(GLuint shaderProgram, const char* name, GLint numComponents, GLenum type, GLsizei stride, int offset)
	GLint attrib = glGetAttribLocation(shaderProgram, name);
	glVertexAttribPointer(attrib, numComponents, type, GL_FALSE, stride, (void*)((intptr_t)offset));

// in main.cpp:

setVertexAttribPointer(skylineShader, "position", 2, GL_FLOAT, 5*sizeof(GLfloat), 0);
setVertexAttribPointer(skylineShader, "color", 3, GL_FLOAT, 5*sizeof(GLfloat), 2*sizeof(GLfloat));

Now I have changed that to:

GLint attrib = glGetAttribLocation(skylineShader, "position");
glEnableVertexArrayAttrib(skylineVAO, attrib);
glVertexArrayVertexAttribOffsetEXT(skylineVAO, skylineBuffer, attrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

I didn’t include the lines setting up the vertex attribute pointers for “color”, as the program crashes after the function call to glVertexArrayVertexAttribOffsetEXT.

Here is more of the context, and here are the functions I used in that code - it should not be necessary to pay too much attention to those.

As you can see, skylineBuffer is the output of glGenBuffers, and it’s sent to glVertexArrayVertexAttribOffsetEXT after uploading the vertices (just the same as in the working test case).

I would greatly appreciate any help that can point me in the right direction.


glEnableVertexArrayAttrib(skylineVAO, attrib);
glVertexArrayVertexAttribOffsetEXT(skylineVAO, skylineBuffer, attrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

You’re combining two different extensions: EXT_direct_state_access and ARB_direct_state_access. While they are similar, there are distinct differences between them. So you may well have confused the implementation by combining two similar-yet-distinct sets of functions. glEnableVertexArrayAttrib is from the ARB extension, while obviously the EXT function is from the EXT extension.

If you’re going to use ARB_DSA, then use that, alone. Which requires the separation of vertex format from buffer bindings.

Thanks for the reply! I’m not sure about the difference between EXT and ARB, but I think I will stay with EXT - then what is the EXT equivalent of glEnableVertexArrayAttrib?

Additional question: in that link, it says that glVertexAttribPointer incorporates both “the vertex format for an attribute array, and the source data for that array”. I’m confused about this, because it does not seem like glVertexAttribPointer deals with the source data at all. You specify an attribute pointer (variable name, shader program), number of components, data type, normalization, stride and offset. Which of these are considered “the source data”? (I automatically think about the actual bytes getting uploaded to the buffer).


The EXT_DSA extension isn’t quite as consistent about its inconsistent nomenclature as the ARB version.

It’s the buffer bound to GL_ARRAY_BUFFER. The offset specified by the “pointer” is an offset into whatever buffer is bound to GL_ARRAY_BUFFER at the time glVertexAttribArray is called. The function basically takes an extra parameter through the global context.

You can think of glVertexAttribArray as being implemented in terms of VertexArrayVertexAttribOffsetEXT:

void glVertexAttribArray(GLuint index​, GLint size​, GLenum type​, GLboolean normalized​, GLsizei stride​, const void *offset​)
  VertexArrayVertexAttribOffsetEXT(GetCurrVAO(), GetCurrBuffer(GL_ARRAY_BUFFER),
    index, size, type, normalized, stride, (GLintptr)offset);

This is a rather late reply - haven’t had time to continue this lately.

I can’t seem to find out what enum array is supposed to be in void EnableVertexArrayEXT(uint vaobj, enum array); I tried to call the function with the same arguments as I had in the ARB function, I also tried GL_TEXTURE_COORD_ARRAY, but both ended in segmentation fault.

Oh, I’m sorry; I read the wrong thing in EXT_DSA. The function you’re looking for is glEnableVertexArrayAttribEXT.

Ah. Well in the end it turned out that my GPU (or some other layer) doesn’t have support for EXT… That said, since it’s so uncertain whether a user has support for the extension, I think I’ll just go without the extension. Thanks for the help anyway!