C++ C++;:在OpenGL绘图循环中分配内存会导致内存损坏

C++ C++;:在OpenGL绘图循环中分配内存会导致内存损坏,c++,memory,memory-management,opengl-es,glibc,C++,Memory,Memory Management,Opengl Es,Glibc,我有一个开放的GL ES主循环,它调用2个函数;绘制和更新,每个循环一次 以下是绘制循环中的代码: float* sample_data = userdata->sample_data; int fft_length = userdata->fft_length; cout << 'a' << endl; cout << fft_length << endl; GLfloat* points = new GLfloat[3 * ff

我有一个开放的GL ES主循环,它调用2个函数;绘制和更新,每个循环一次

以下是绘制循环中的代码:

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
float*sample\u data=userdata->sample\u data;
int fft_length=userdata->fft_length;

你能用
float(ix)
打字吗?为什么不使用
(float)ix
?@mch我不知道有什么不同?除了第二个与C编译器配合使用外,它是绑定到GL_数组_缓冲区的缓冲区​?@棘轮怪胎听起来可能是错误的原因。你说的是哪个缓冲区,你认为缺少的代码是什么?添加一个
glBindBuffer(GL\u ARRAY\u buffer,0)在调用
glvertexattributepointer
之前