-1

I am working with the Microsoft samples from their GitHub page and even though my code is based off theirs I am not reaching the same result. Both projects have these ComPtrs yet in mine they all are null (0x0000000000000000) while in the sample they work perfectly fine.

ComPtr<IDXGISwapChain3> m_swapChain;
ComPtr<ID3D12Device> m_device;
ComPtr<ID3D12Resource> m_renderTargets[FrameCount];
ComPtr<ID3D12CommandAllocator> m_commandAllocator;
ComPtr<ID3D12CommandQueue> m_commandQueue;
ComPtr<ID3D12DescriptorHeap> m_rtvHeap;
ComPtr<ID3D12PipelineState> m_pipelineState;
ComPtr<ID3D12GraphicsCommandList> m_commandList;

Specifically this line causes the debugger to break.

ThrowIfFailed(m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)));

Edit: My code was incorrectly creating m_device which caused the error.

  • You have only shown the variable declarations, there is no way for anyone to know why they haven't been set to non-null values. You need to show more of your code. – The Dark May 04 '16 at 01:25
  • Where is the code that initializes `m_device` before calling `m_device->CreateCommandQueue()`? – Remy Lebeau May 04 '16 at 04:01

1 Answers1

0

My guess is that you are getting a failed HRESULT back from CreateCommandQueue. You should set the debugger to break on exceptions (see MSDN). Alternatively, you can rewrite it to:

HRESULT hr = m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue));
ThrowIfFailed(hr);

And set a debug break-point on the HRESULT hr = ... line.

As someone noted, make sure you have checked for all possible failure conditions before this point. For some robust code for creating a Direct3D 12 device, see DeviceResources or the VS Direct3D 12 Game templates

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • This assumes `m_device` was initialized to a non-null value to begin with. – Remy Lebeau May 04 '16 at 04:00
  • True enough. As I've stated in many a SO thread, you have to check the return value of anything that has an ``HRESULT`` for failure using ``SUCCEDED`` or ``FAILED`` macro or something like [ThrowIfFailed](https://github.com/Microsoft/DirectXTK/wiki/ThrowIfFailed). You can't ignore the return value. – Chuck Walbourn May 04 '16 at 04:30