GlTexImage3D crash in QT

Below is a piece of code. There are no problems compiling, but they fail when executed. And it breaks in the glTexImage3D line. Qt is version 4.5.3, and the "opengl" class inherits from QGLWidget.

void opengl::initializeGL()
{
    GLenum err = glewInit();
    create_volumetexture();
}

void opengl::create_volumetexture()
{   
    int w = 256, h = 256, d = 225;
    size_t size = w * h * d;

    if (dataRGBA)
    {
        delete dataRGBA;
        dataRGBA=NULL;
    }
    dataRGBA=new GLubyte[4*size];
    for (int i=0; i<size; i++)
    {
        dataRGBA[4*i]=200;
        dataRGBA[4*i+1]=0;
        dataRGBA[4*i+2]=0;
        dataRGBA[4*i+3]=100;
    }

    glGenTextures(1, &volume_texture);
    // bind 3D texture target
    glBindTexture(GL_TEXTURE_3D, volume_texture);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);

    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    glTexImage3D(GL_TEXTURE_3D_EXT, 0, GL_RGBA, w, h, d, 1, /*GL_LUMINANCE*/GL_RGBA, GL_UNSIGNED_BYTE,dataRGBA);

}
+3
source share
1 answer

You gave a nonzero value to the border parameter, but the buffer allocated for it does not take it into account, therefore glTexImage3D performs a buffer overflow.

d , . glTexImage3D glTexSubImage3D, - , glTexSubImage, 2- ( 2 ... ).

+3

Source: https://habr.com/ru/post/1779712/


All Articles