diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index a1bbc1d282c..db85730040e 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -4306,7 +4306,6 @@ QRhiResource::Type QRhiCommandBuffer::resourceType() const return CommandBuffer; } -#ifndef QT_NO_DEBUG static const char *resourceTypeStr(QRhiResource *res) { switch (res->resourceType()) { @@ -4340,7 +4339,6 @@ static const char *resourceTypeStr(QRhiResource *res) } return ""; } -#endif QRhiImplementation::~QRhiImplementation() { @@ -4350,7 +4348,13 @@ QRhiImplementation::~QRhiImplementation() // this far with some backends where the allocator or the api may check // and freak out for unfreed graphics objects in the derived dtor already. #ifndef QT_NO_DEBUG - if (!resources.isEmpty()) { + // debug builds: just do it always + static bool leakCheck = true; +#else + // release builds: opt-in + static bool leakCheck = qEnvironmentVariableIntValue("QT_RHI_LEAK_CHECK"); +#endif + if (leakCheck && !resources.isEmpty()) { qWarning("QRhi %p going down with %d unreleased resources that own native graphics objects. This is not nice.", q, int(resources.count())); for (QRhiResource *res : qAsConst(resources)) { @@ -4358,7 +4362,6 @@ QRhiImplementation::~QRhiImplementation() res->m_rhi = nullptr; } } -#endif } bool QRhiImplementation::isCompressedFormat(QRhiTexture::Format format) const