You are using the following line in the initialization:
glBufferData(GL_ARRAY_BUFFER, 12*sizeof(GLfloat), data.data(), GL_STATIC_DRAW);
When drawing you set up your attrib pointers like this:
glVertexPointer(3, GL_FLOAT, 0, data.data());
I suspect that data.data()
is the same in both cases - making this an error. When an ARRAY_BUFFER
is bound, the pointer argument of the various gl*Pointer()
functions does not refer to a client memory address, but to a byte offset in the VBOs. When drawing, the GL will try to fetch this data which is very likely to be way out of bounds of the buffer object - hence the crash. You probably meant:
glVertexPointer(3, GL_FLOAT, 0, NULL);
Note that the original VBO extension has this often-used macro in the examples section:
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
Using that, you can conveniently hide those ugly pointer arithmetic nicely and can address byte offsets in your buffer:
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));