diff options
author | Marc Mutz <[email protected]> | 2025-03-10 10:27:31 +0100 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2025-03-10 21:14:20 +0100 |
commit | 7a1cd692e0b36acfc005332b50d7ef3e11b94e71 (patch) | |
tree | 4f0fab7b3cfe6f58be8af442352ee0a530a348ce /tests/auto/gui/qopengl/tst_qopengl.cpp | |
parent | 75df3a250d84a7e2680a8f229d11eec20b2d3ff0 (diff) |
tst_QOpenGL: don't leak 1399341 byte(s) [...] in 1439 allocation(s)
That's what asan reported for a run of this test executable.
Create `ctx` on the stack instead of the heap to fix the leaks.
For `fbo`, use a std::optional.
After these fixes, the test still leaks 64 bytes in 2
allocations. These seem to be QOpenGLSharedResourceGuards in a
QOpenGLFramebufferObject. Created QTBUG-134557 to track the issue.
Amends
- 68974d8e647febb80a47d9cf6ce9452f3ce4fa21 (fboHandleNulledAfterContextDestroyed())
- bb760d9514ed617ee8e7344152b3fa697b2c4171 (bufferMapRange()/bufferCreate())
- 0541516907da117c391b6c8d9820209673fcd9cd (vaoCreate())
Pick-to: 6.9 6.8 6.5 5.15
Task-number: QTBUG-134557
Change-Id: Icc318cd76b9f3ddf71bc294cb96d88485c42d7bc
Reviewed-by: Laszlo Agocs <[email protected]>
Diffstat (limited to 'tests/auto/gui/qopengl/tst_qopengl.cpp')
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 3f4aa8cd8f9..4cc2dc49027 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -29,6 +29,8 @@ #include <QSignalSpy> +#include <optional> + Q_DECLARE_METATYPE(QImage::Format) class tst_QOpenGL : public QObject @@ -770,7 +772,7 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() window.setGeometry(0, 0, 10, 10); window.create(); - QOpenGLFramebufferObject *fbo = 0; + std::optional<QOpenGLFramebufferObject> fbo; { QOpenGLContext ctx; @@ -781,11 +783,12 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); - fbo = new QOpenGLFramebufferObject(128, 128); + fbo.emplace(128, 128); QVERIFY(fbo->handle() != 0); } + QVERIFY(fbo); QCOMPARE(fbo->handle(), 0U); } @@ -1557,30 +1560,30 @@ void tst_QOpenGL::wglContextWrap() void tst_QOpenGL::vaoCreate() { QScopedPointer<QSurface> surface(createSurface(QSurface::Window)); - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(surface.data()); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); QOpenGLVertexArrayObject vao; bool success = vao.create(); - if (ctx->isOpenGLES()) { - if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) + if (ctx.isOpenGLES()) { + if (ctx.format().majorVersion() >= 3 || ctx.hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) QVERIFY(success); } else { - if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) + if (ctx.format().majorVersion() >= 3 || ctx.hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) QVERIFY(success); } vao.destroy(); - ctx->doneCurrent(); + ctx.doneCurrent(); } void tst_QOpenGL::bufferCreate() { QScopedPointer<QSurface> surface(createSurface(QSurface::Window)); - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(surface.data()); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); QOpenGLBuffer buf; @@ -1607,17 +1610,17 @@ void tst_QOpenGL::bufferCreate() buf.destroy(); QVERIFY(!buf.isCreated()); - ctx->doneCurrent(); + ctx.doneCurrent(); } void tst_QOpenGL::bufferMapRange() { QScopedPointer<QSurface> surface(createSurface(QSurface::Window)); - QOpenGLContext *ctx = new QOpenGLContext; - ctx->create(); - ctx->makeCurrent(surface.data()); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); - QOpenGLExtensions funcs(ctx); + QOpenGLExtensions funcs(&ctx); if (!funcs.hasOpenGLExtension(QOpenGLExtensions::MapBufferRange)) QSKIP("glMapBufferRange not supported"); @@ -1643,7 +1646,7 @@ void tst_QOpenGL::bufferMapRange() buf.unmap(); buf.destroy(); - ctx->doneCurrent(); + ctx.doneCurrent(); } void tst_QOpenGL::defaultQGLCurrentBuffer() |