From 0f778de5bb1f553e21c012047e1282908d64fe68 Mon Sep 17 00:00:00 2001 From: HengHui Date: Wed, 22 Feb 2023 01:14:08 +0800 Subject: [PATCH] Fix potential crash for sample D3D12nBodyGravity Array renderContextFenceValues[ThreadCount] has only one element. D3D12nBodyGravity::WaitForGpu() accesses the second element of array renderContextFenceValues[ThreadCount] when m_frameIndex is 1. This logic is wrong, m_renderContextFenceValue would be the right fence value to be waited. --- Samples/Desktop/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp | 6 +++--- Samples/UWP/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Samples/Desktop/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp b/Samples/Desktop/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp index 1cc2531c0..4dac43cbf 100644 --- a/Samples/Desktop/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp +++ b/Samples/Desktop/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp @@ -698,14 +698,14 @@ void D3D12nBodyGravity::RestoreD3DResources() void D3D12nBodyGravity::WaitForGpu() { // Schedule a Signal command in the queue. - ThrowIfFailed(m_commandQueue->Signal(m_renderContextFence.Get(), m_renderContextFenceValues[m_frameIndex])); + ThrowIfFailed(m_commandQueue->Signal(m_renderContextFence.Get(), m_renderContextFenceValue)); // Wait until the fence has been processed. - ThrowIfFailed(m_renderContextFence->SetEventOnCompletion(m_renderContextFenceValues[m_frameIndex], m_renderContextFenceEvent)); + ThrowIfFailed(m_renderContextFence->SetEventOnCompletion(m_renderContextFenceValue, m_renderContextFenceEvent)); WaitForSingleObjectEx(m_renderContextFenceEvent, INFINITE, FALSE); // Increment the fence value for the current frame. - m_renderContextFenceValues[m_frameIndex]++; + m_renderContextFenceValue++; } // Fill the command list with all the render commands and dependent state. diff --git a/Samples/UWP/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp b/Samples/UWP/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp index 92b9f4d49..a58b43c5b 100644 --- a/Samples/UWP/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp +++ b/Samples/UWP/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp @@ -694,14 +694,14 @@ void D3D12nBodyGravity::RestoreD3DResources() void D3D12nBodyGravity::WaitForGpu() { // Schedule a Signal command in the queue. - ThrowIfFailed(m_commandQueue->Signal(m_renderContextFence.Get(), m_renderContextFenceValues[m_frameIndex])); + ThrowIfFailed(m_commandQueue->Signal(m_renderContextFence.Get(), m_renderContextFenceValue)); // Wait until the fence has been processed. - ThrowIfFailed(m_renderContextFence->SetEventOnCompletion(m_renderContextFenceValues[m_frameIndex], m_renderContextFenceEvent)); + ThrowIfFailed(m_renderContextFence->SetEventOnCompletion(m_renderContextFenceValue, m_renderContextFenceEvent)); WaitForSingleObjectEx(m_renderContextFenceEvent, INFINITE, FALSE); // Increment the fence value for the current frame. - m_renderContextFenceValues[m_frameIndex]++; + m_renderContextFenceValue++; } // Fill the command list with all the render commands and dependent state.