-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
5.2.0
-
None
-
OS: Win 8 Pro x64
OpenGL: 4.3 (using in program 4.2)
Hi,
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())
}
textures.append(qMakePair<QString, TexturePtr>(textureName, texture));
}
Here you can visit part of destructor in QOpenGLTexture [qt.gitorious.org] to source code)
https://qt.gitorious.org/qt/qtbase/source/fc10bfd55035d27c9352c1678c3aad87c4be2e09:src/gui/opengl/qopengltexture.cpp#L131-244 line 181:
void QOpenGLTexturePrivate::destroy()
{
if (QOpenGLContext::currentContext() != context)
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.