Hey,
When I'm trying to execute my program, I get this error: "malloc: *** error for object 0x100d8b770: pointer being freed was not allocated". I used gdb to see the stacktrace:
#0 0x00007fff8c260866 in __pthread_kill ()
#1 0x00007fff8bcf135c in pthread_kill ()
#2 0x00007fff8c217bba in abort ()
#3 0x00007fff8b468093 in free ()
#4 0x0000000100001aae in Render::renderLoop ()
#5 0x0000000100001470 in RenderWindow::show ()
#6 0x0000000100000fab in main ()
The problem seems to come from the methode renderLoop() of the class Render. Here is the code of that method:
void Render::renderLoop(GLFWwindow* window) {
Cube cube;
float *points = cube.getArrayOfPoints();
unsigned int vertexArrayObject = 0;
glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);
unsigned int vertexBufferObject = 0;
glGenBuffers(1, &vertexBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, cube.getSize() * 3 * sizeof(float), points, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
// Vertex Shader
std::string vertex_shader_file = readShaderFile("shader/test_vs.glsl");
const char* vertex_shader = vertex_shader_file.c_str();
// Fragment Shader
std::string fragment_shader_file = readShaderFile("shader/test_fs.glsl");
const char* fragment_shader = fragment_shader_file.c_str();
unsigned int vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, &vertex_shader, NULL);
glCompileShader(vs);
unsigned int fs = glCreateShader (GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, &fragment_shader, NULL);
glCompileShader(fs);
unsigned int shader_programme = glCreateProgram();
glAttachShader(shader_programme, fs);
glAttachShader(shader_programme, vs);
glLinkProgram(shader_programme);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
while (!glfwWindowShouldClose(window)) {
// Wipe the drawing surface clear
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Viewport
glViewport(0, 0, getWindowWidth(), getWindowHeight());
// Draw
//draw();
glUseProgram(shader_programme);
glBindVertexArray(vertexArrayObject);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
// Update other events like input handling
glfwPollEvents();
// Put the stuff we've been drawing onto the display
glfwSwapBuffers(window);
}
}
I don't see where my pointer points is being freed :/ Would you have any idea ?
Thanks in advance !