_device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&CD3DX12_RESOURCE_DESC::Buffer(byteSize),
D3D12_RESOURCE_STATE_COMMON,
nullptr,
IID_PPV_ARGS(defaultBuffer));
When I try to reproduce this code in my project, I get this error: C2102 '&' requires l-value.
I have brief understanding of all r/l -value stuff (though I am no expert).
Function signature:
HRESULT CreateCommittedResource( const D3D12_HEAP_PROPERTIES *pHeapProperties, D3D12_HEAP_FLAGS HeapFlags,
const D3D12_RESOURCE_DESC *pDesc,
D3D12_RESOURCE_STATES InitialResourceState,
const D3D12_CLEAR_VALUE *pOptimizedClearValue,
REFIID riidResource,
_COM_Outptr_opt_ void **ppvResource)
The error, obviously, is about the 1st and the 3rd parameters.
As far as I understand, calling a class constructor within function call scope creates a temporary variable which expires as soon as the the execution flow moves to the called function body, so using a pointer to it within the function body is wrong (it "points" to a destructed value).
What's more surprising, I have obtained the guidebook sample code. I compiled it and it's OK, there are no errors. Moreover, the program runs OK (everything is drawn properly), so my thoughts on dangling pointer were wrong. I want to understand the thing and hear opinion from an experienced coder.
I suspect that maybe some errors have been suppresed via ProjectSettings. Or else, it has to do something with out-dated SDK version or older compiler (v140) I had to install to run the sample.
I can apply sample code if necessary.
0 comments:
Post a Comment
Thanks