Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

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

$
0
0
Hi, This class appear in Qt 5.2 and I think I found critical bug. I have simple inherited class called Texture Texture.h class Texture : public QOpenGLTexture { public:     Texture(const QImage& image, MipMapGeneration genMipMaps = GenerateMipMaps);     ~Texture();       const QImage getImage();   private:     QOpenGLFunctions_4_2_Core* GLfuncs; };   typedef QSharedPointer<Texture> TexturePtr; Texture.cpp Texture::Texture(const QImage& image, MipMapGeneration genMipMaps) : QOpenGLTexture(image, genMipMaps) {     QOpenGLContext* context = QOpenGLContext::currentContext();       Q_ASSERT(context);       GLfuncs = context->versionFunctions<QOpenGLFunctions_4_2_Core>();     GLfuncs->initializeOpenGLFunctions(); }   Texture::~Texture() {     //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;      bind();      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! TextureManager.cpp 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               return;         }     }       textures.append(qMakePair<QString, TexturePtr>(textureName, texture)); } Here you can visit part of destructor in QOpenGLTexture [qt.gitorious.org] 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");         return;     }       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. Thanks.

Viewing all articles
Browse latest Browse all 13965

Latest Images

Trending Articles



Latest Images