From ecb0aa5f1116824286b764e136d5ec198b1a1995 Mon Sep 17 00:00:00 2001 From: Piotr Srebrny Date: Fri, 11 Feb 2022 14:17:20 +0100 Subject: Do not access NV_DX_interop functions out of OpenGL context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An attempt to use NV_DX_interop functions out of OpenGL context results in an exception. Thus, we do not unregister the D3D9 texture from the OpenGL context when it is gone. This patch also clears m_glHandle variable after it has been unregister in some rare case when we cannot lock it. Fixes: QTBUG-100665 Change-Id: Ie4bc02dbaccec12d92f8e274eeb420482a5f2d58 Reviewed-by: André de la Rocha Reviewed-by: Lars Knoll (cherry picked from commit 3893a5b88349f4086e003c3f51cffdf538131c6c) --- .../platform/windows/evr/evrd3dpresentengine.cpp | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/multimedia/platform/windows/evr/evrd3dpresentengine.cpp b/src/multimedia/platform/windows/evr/evrd3dpresentengine.cpp index 9cf4846a7..5a975f09e 100644 --- a/src/multimedia/platform/windows/evr/evrd3dpresentengine.cpp +++ b/src/multimedia/platform/windows/evr/evrd3dpresentengine.cpp @@ -181,26 +181,27 @@ public: ~OpenGlVideoBuffer() override { - if (m_d3dglHandle) { + if (!m_d3dglHandle) + return; + + if (QOpenGLContext::currentContext()) { if (m_glHandle) { if (!m_wgl.wglDXUnlockObjectsNV(m_d3dglHandle, 1, &m_glHandle)) qCDebug(qLcEvrD3DPresentEngine) << "Failed to unlock OpenGL texture"; if (!m_wgl.wglDXUnregisterObjectNV(m_d3dglHandle, m_glHandle)) qCDebug(qLcEvrD3DPresentEngine) << "Failed to unregister OpenGL texture"; - if (QOpenGLContext::currentContext()) { - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - if (funcs) - funcs->glDeleteTextures(1, &m_glTextureName); - else - qCDebug(qLcEvrD3DPresentEngine) << "Could not delete texture, OpenGL context functions missing"; - } else { - qCDebug(qLcEvrD3DPresentEngine) << "Could not delete texture, OpenGL context missing"; - } + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + if (funcs) + funcs->glDeleteTextures(1, &m_glTextureName); + else + qCDebug(qLcEvrD3DPresentEngine) << "Could not delete texture, OpenGL context functions missing"; } - if (!m_wgl.wglDXCloseDeviceNV(m_d3dglHandle)) qCDebug(qLcEvrD3DPresentEngine) << "Failed to close D3D-GL device"; + + } else { + qCDebug(qLcEvrD3DPresentEngine) << "Could not release texture, OpenGL context missing"; } } @@ -245,6 +246,7 @@ public: qCDebug(qLcEvrD3DPresentEngine) << "Failed to lock OpenGL texture"; m_wgl.wglDXUnregisterObjectNV(m_d3dglHandle, m_glHandle); + m_glHandle = nullptr; } else { qCDebug(qLcEvrD3DPresentEngine) << "Could not register D3D9 texture in OpenGL"; } -- cgit v1.2.3