The WaitForSingleObject function causes the following error
Exception thrown at 0x00007FFA02794AD0 (d3d12warp.dll) in DrawTexturedCube.exe: 0xC0000005: Access violation reading location 0x0000000000000000
while waiting for the previous frame to complete. The Code is taken from the MSDN DirectX12 Example Code (https://msdn.microsoft.com/en-us/library/windows/desktop/dn899189%28v=vs.85%29.aspx).
void D3D12RenderSystem::waitForPreviousFrame() {
const UINT fence = fenceValue_;
ThrowIfFailed(commandQueue_->Signal(fence.Get(), fence));
fenceValue_++;
if (fence_->GetCompletedValue() < fence) {
ThrowIfFailed(fence_->SetEventOnCompletion(fence, fenceEvent_));
WaitForSingleObject(fenceEvent_, INFINITE);
}
frameIndex_ = swapChain_->GetCurrentBackBufferIndex();
}
This error does only occur in 1 of 4 test cases. The access violation disappears (but so does the image rendered to the Viewport) if I remove the call to the following function from the paintEvent loop, which is structured as described here (https://msdn.microsoft.com/de-de/library/windows/desktop/dn903899%28v=vs.85%29.aspx).
void D3D12CommandList::setScissorRect(const int width, const int height) {
D3D12_RECT rectScissor = { 0.0f, //top
0.0f, //left
static_cast<LONG>(width), //right
static_cast<LONG>(height)}; //bottom
commandList_->RSSetScissorRects(1, &rectScissor);
}
I'm using VS2015 and the debugger isn't showing the fenceEvent_ variable as NULL in all test cases and the disassembly shows ?? ?? for the memory where the handle points to in all test cases. My shaders don't use geometry shaders.
So now I have 2 questions:
- How can the WaitForSingleObject function lead to an access violation in only 1 out of 4 nearly identical test cases?
- How are the RSSetScissorRects function and the WaitForSingleObject function related to each other?