I have an Open GL ES main loop, which calls 2 functions; draw and update, once each per loop.
The following is the code from the draw loop:
float* sample_data = userdata->sample_data;
int fft_length = userdata->fft_length;
cout << 'a' << endl;
cout << fft_length << endl;
GLfloat* points = new GLfloat[3 * fft_length];
cout << 'b' << endl;
// Draw tingz
for(int ix = 0; ix < fft_length; ++ ix)
{
float ratio = float(ix) / float(fft_length - 1);
float x = -1.0 + 2.0 * ratio;
float y = sample_data[ix];
points[3 * ix + 0] = x;
points[3 * ix + 1] = y;
points[3 * ix + 2] = 0.0;
}
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, points);
glEnableVertexAttribArray(0);
glDrawArrays(GL_LINE_STRIP, 0, fft_length);
std::cout << 'd' << std::endl;
delete [] points;
std::cout << 'e' << std::endl;
// End of function
The output prints everything once, but then only prints a
and 256
, which is the length of the fft.
Hence I assume it is the call to 'new' where the problem occurs. The next line of text on the screen which appears is:
*** glibc detected *** ./main.out: malloc(): memory corruption: 0x01319648 ***
This puzzles me, as I can't immediately see anything wrong. I allocate memory and delete it again. My guess is I made a stupid mistake which I just can't spot?