[Qt 5.2][QOpenGLTexture][BUG?] Texture has not been destroyed

  • Hi,

    This class appear in Qt 5.2 and I think I found critical bug.

    I have simple inherited class called Texture

    @class Texture : public QOpenGLTexture
    Texture(const QImage& image, MipMapGeneration genMipMaps = GenerateMipMaps);

    const QImage getImage();

    QOpenGLFunctions_4_2_Core* GLfuncs;

    typedef QSharedPointer<Texture> TexturePtr;@

    @Texture::Texture(const QImage& image, MipMapGeneration genMipMaps)
    : QOpenGLTexture(image, genMipMaps)
    QOpenGLContext* context = QOpenGLContext::currentContext();

    GLfuncs = context->versionFunctions<QOpenGLFunctions_4_2_Core>();


    //destroy(); // don't crash, show warning in debug "Requires a valid current OpenGL context.
    Texture has not been destroyed"
    //QOpenGLTexture::~QOpenGLTexture(); // crash, show warning in debug like destroy

    const QImage Texture::getImage()
    int width, height;

    GLfuncs->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,  &width);
    GLfuncs->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
    if(width <= 0 || height <= 0)
        return QImage();
    GLint bytes = width * height * 4;
    unsigned char* data = (unsigned char*)malloc(bytes);
    GLfuncs->glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
    QImage img = QImage(data, width, height, QImage::Format_RGBA8888);
    return img;


    There is also my code where I loading texture into memory, if texture is already in TextureManager I'm trying to destroy it, and here become problem!

    @void TextureManager::loadTexture(QString textureName, QString texturePath)
    QImage textureImage(texturePath);

    TexturePtr texture(new Texture(textureImage.mirrored()));
    QPair<QString, TexturePtr> pair;
    foreach(pair, textures)
        if(textureName == pair.first && texturePath == pair.second->getPath())
            texture->destroy(); // point of crash
    textures.append(qMakePair<QString, TexturePtr>(textureName, texture));


    Here you can visit part of destructor in "QOpenGLTexture ":https://qt.gitorious.org/qt/qtbase/raw/fc10bfd55035d27c9352c1678c3aad87c4be2e09:src/gui/opengl/qopengltexture.cpp(link to source code):
    @void QOpenGLTexturePrivate::destroy()
    if (QOpenGLContext::currentContext() != context) { // WTF? this "context" using some QOpenGLTextureHelper which cant be possible in QOpenGLContext::currentContext so this will never be true!
    qWarning("Requires a valid current OpenGL context.\n"
    "Texture has not been destroyed");

    texFuncs->glDeleteTextures(1, &textureId);@

    I'm using QGLWidget, calling this->makeCurrent(), then initializing TextureManager, next line = textureManager->loadTexture("Example", "pathToTexture.png");

    I don't know who wrote this class, so I can't contact him and consulate if it is really bug or critical error or something like that.


  • Lifetime Qt Champion


    To reach Qt's developers/maintainers, you should ask on the interest mailing list (this forum is more user oriented)

  • Where I can find this mailing list?

  • Lifetime Qt Champion

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.