From 2d9c229eaa1f83bbeec07285b8646c9db6fb081e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 21 Apr 2021 13:12:56 +0200 Subject: [PATCH] [d3d11] Add range checking to SOGetTargets --- src/d3d11/d3d11_context.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 62ff7ae4..5afc0a14 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -3062,8 +3062,11 @@ namespace dxvk { ID3D11Buffer** ppSOTargets) { D3D10DeviceLock lock = LockContext(); - for (uint32_t i = 0; i < NumBuffers; i++) - ppSOTargets[i] = m_state.so.targets[i].buffer.ref(); + for (uint32_t i = 0; i < NumBuffers; i++) { + ppSOTargets[i] = i < m_state.so.targets.size() + ? m_state.so.targets[i].buffer.ref() + : nullptr; + } } @@ -3074,11 +3077,19 @@ namespace dxvk { D3D10DeviceLock lock = LockContext(); for (uint32_t i = 0; i < NumBuffers; i++) { - if (ppSOTargets != nullptr) - ppSOTargets[i] = m_state.so.targets[i].buffer.ref(); + const bool inRange = i < m_state.so.targets.size(); - if (pOffsets != nullptr) - pOffsets[i] = m_state.so.targets[i].offset; + if (ppSOTargets != nullptr) { + ppSOTargets[i] = inRange + ? m_state.so.targets[i].buffer.ref() + : nullptr; + } + + if (pOffsets != nullptr) { + pOffsets[i] = inRange + ? m_state.so.targets[i].offset + : 0u; + } } }