在 OpenGL3 中绘制线条时出现内存泄漏

问题描述

我的画线功能出现了一些内存泄漏问题。 我正在使用 Windows 任务管理器查看有问题。当我启动应用程序时,它使用了大约 200MB,运行它大约 10 分钟后,它使用了大约 10GB(当我停止绘制线条时停止)。

我的画线功能看起来像:

static unsigned int buffer;
void drawLine(float x1,float y1,float x2,float y2,float r,float g,float b,float a)
{
    x1 = pixToPointWidth(x1,width);
    y1 = pixToPointHeight(y1,height);
    x2 = pixToPointWidth(x2,width);
    y2 = pixToPointHeight(y2,height);

    float pos[12] = {
        x1,y1,r,g,b,a,x2,y2,a
    };

    glGenBuffers(1,&buffer);
    glBindBuffer(GL_ARRAY_BUFFER,buffer);
    glBufferData(GL_ARRAY_BUFFER,sizeof(pos),pos,GL_STATIC_DRAW);

    glEnabLevertexAttribArray(0);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,sizeof(float) * 6,0);

    glEnabLevertexAttribArray(1);
    glVertexAttribPointer(1,4,(const void*)8);

    if (!createdShader)
    {
        createShader();
    }

    gluseProgram(shader);
    glDrawArrays(GL_LInes,2);
}

它在 1ms 睡眠的 while(true) 循环中被调用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)