Fix in AllocatorPimpl::GetResourceAllocationInfoMiddle When GetResourceAllocationInfo fails, it returns SizeInBytes == UINT64_MAX. Also a fix in TestDevice12 for cases when it fails.
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index ffa5e0f..653a2f8 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp
@@ -7722,7 +7722,7 @@ } outAllocInfo = GetResourceAllocationInfoNative(inOutResourceDesc); - return S_OK; + return outAllocInfo.SizeInBytes != UINT64_MAX ? S_OK : E_INVALIDARG; } #ifdef __ID3D12Device8_INTERFACE_DEFINED__ @@ -7738,7 +7738,7 @@ if (m_Device12 != NULL) { outAllocInfo = GetResourceAllocationInfo3Native(inOutResourceDesc, NumCastableFormats, pCastableFormats); - return S_OK; + return outAllocInfo.SizeInBytes != UINT64_MAX ? S_OK : E_INVALIDARG; } #else return E_NOTIMPL; @@ -7746,7 +7746,7 @@ } outAllocInfo = GetResourceAllocationInfo2Native(inOutResourceDesc); - return S_OK; + return outAllocInfo.SizeInBytes != UINT64_MAX ? S_OK : E_INVALIDARG; } #endif // #ifdef __ID3D12Device8_INTERFACE_DEFINED__
diff --git a/src/Tests.cpp b/src/Tests.cpp index c704e1e..b7db1be 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp
@@ -3152,10 +3152,18 @@ ComPtr<D3D12MA::Allocation> alloc0; ComPtr<ID3D12Resource> res0; - CHECK_HR(ctx.allocator->CreateResource3(&allocDesc, &resourceDesc, + HRESULT hr = ctx.allocator->CreateResource3(&allocDesc, &resourceDesc, D3D12_BARRIER_LAYOUT_UNDEFINED, NULL, _countof(castableFormats), castableFormats, - &alloc0, IID_PPV_ARGS(&res0))); + &alloc0, IID_PPV_ARGS(&res0)); + + if (hr == E_INVALIDARG) + { + wprintf(L"Allocator::CreateResource3 failed with E_INVALIDARG!\n"); + return; + } + + CHECK_HR(hr); CHECK_BOOL(alloc0 && res0); } #endif // #ifdef __ID3D12Device12_INTERFACE_DEFINED__