Isaac Dexter
Isaac Dexter

Reputation: 23

Access violation when calling ClearDepthStencilView in DX12

I'm trying to learn DirectX12 and have been following along with 3dgep's tutorial.

When I attempt to clear the depth stencil view, it works fine on the first call but throws

Exception thrown at 0x00007FFA81B8D62C (nvwgf2umx.dll) in ARTG.exe: 0xC0000005: Access violation reading location 0x000000000000008C.

on subsequent calls.

I currently clear the depth stencil like so:

// get a fresh command list, which will've been automatically reset
ComPtr<ID3D12GraphicsCommandList2> commandList = m_directCommandQueue->GetCommandList();

D3D12_CPU_DESCRIPTOR_HANDLE dsv = m_DSVHeap->GetCPUDescriptorHandleForHeapStart();
commandList->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);

I use the same command list for clearing the render target view on the previous line. m_DSVHeap is a Microsoft::WRL::ComPtr<ID3D12DescriptorHeap>, and is created as follows:

// create descriptor heap for depth-stencil view
D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
dsvHeapDesc.NumDescriptors = 1; // only the depth stencil view needs to be on the heap
dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;  // DSV descriptor heap
dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;    // shader flags do not apply to DSV heaps as shaders do not reference them
ThrowIfFailed(m_device->CreateDescriptorHeap(&dsvHeapDesc, IID_PPV_ARGS(&m_DSVHeap)));  // create descriptor heap from descriptor

I'm mostly trying to find out if there's an essential step I've missed, I don't understand why it doesn't throw an exception on the first frame.

Upvotes: 1

Views: 159

Answers (0)

Related Questions