Recently I got a segfault when reading atomic counters via glMapBuffer. Here is the code:
GLuint atomicCounter[2];
inline void getAtomicCounters()
{
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, ATOMIC_COUNTER_INDEX, acBuffer);
CHECK_FOR_GL_ERRORS();
static GLuint* data = (GLuint*)glMapBuffer(GL_ATOMIC_COUNTER_BUFFER, GL_READ_ONLY);
CHECK_FOR_GL_ERRORS();
atomicCounter[0] = data[0];
atomicCounter[1] = data[1];
glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
CHECK_FOR_GL_ERRORS();
}
The problem seems to be that data is a static pointer. When I remove the static keyword, everything works perfectly. I know that I don't need a static pointer, it was just a test and I'm quite surprised that it won't work with a static pointer. Does anybody know why a segfault occurs at "atomicCounter[0] = data[0];"?