Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.4, 6.2.0 FF, 6.3.0
-
None
Description
In qopenglframebufferobject.cpp, line 600 a QOpenGLSharedResourceGuard is allocated. In line 1313 ( takeTexture() ) the corresponding pointer is simply set to NULL without deleting the guard - finally ending up as memory leak.
IMHO a better solution would be to call invalidateResource(). Then the guard will properly be deleted without releasing the taken texture.
In my code QOpenGLFramebufferObject::takeTexture() is called for every update of a texture and the leaks are summing up siginficantly.
My ( nicht jugendfreier ) workaround looks like this:
#include <private/qopenglframebufferobject_p.h> GLuint qskTakeTexture( QOpenGLFramebufferObject& fbo ) { class MyFBO { public: virtual ~MyFBO() = default; QScopedPointer<QOpenGLFramebufferObjectPrivate> d_ptr; }; static_assert( sizeof( MyFBO ) == sizeof( QOpenGLFramebufferObject ), "Bad cast: QOpenGLFramebufferObject does not match" ); auto& attachment = reinterpret_cast< MyFBO* >( &fbo )->d_ptr->colorAttachments[0]; auto guard = attachment.guard; const auto textureId = fbo.takeTexture(); if ( guard ) { class MyGuard : public QOpenGLSharedResourceGuard { public: void invalidateTexture() { invalidateResource(); } }; reinterpret_cast< MyGuard* >( guard )->invalidateTexture(); } attachment.guard = guard; return textureId; }