diff options
author | Piotr Srebrny <piotr.srebrny@qt.io> | 2022-02-11 14:17:20 +0100 |
---|---|---|
committer | Piotr Srebrny <piotr.srebrny@qt.io> | 2022-02-16 20:37:20 +0100 |
commit | ecb0aa5f1116824286b764e136d5ec198b1a1995 (patch) | |
tree | 1d2ba5fe2ea34db21776f3a8a072df6110063c9f | |
parent | 14758a8ea3a2e93e5809e36cf0350e1838b37734 (diff) | |
download | qtmultimedia-ecb0aa5f1116824286b764e136d5ec198b1a1995.tar.gz |
Do not access NV_DX_interop functions out of OpenGL context
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 <andre.rocha@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit 3893a5b88349f4086e003c3f51cffdf538131c6c)
-rw-r--r-- | src/multimedia/platform/windows/evr/evrd3dpresentengine.cpp | 24 |
1 files 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"; } |