OpenGL or SDL segfaults when it reaches the very first statement in the class. I have no idea what is causing it.
class RenderEngine {
GLuint vertexArrayId;
GLfloat[] vertexBufferData = [
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f
];
GLuint vertexBufferId;
public this() {
glGenVertexArrays(1, &vertexArrayId); // SEGMENTATION FAULT / RETURN -11
glBindVertexArray(vertexArrayId);
glGenBuffers(1, &vertexBufferId);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
glBufferData(GL_ARRAY_BUFFER, vertexBufferData.length * GLfloat.sizeof, vertexBufferData.ptr, GL_STATIC_DRAW);
}
public void render() {
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…