terrafx / terrafx.interop.windows

Interop bindings for Windows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

D3D12_RT_FORMAT_ARRAY constructor is incorrect and corrupts memory

Marlax0 opened this issue · comments

The constructor for D3D12_RT_FORMAT_ARRAY has its Buffer.MemoryCopy 'source' and 'destination' parameters swapped.

public unsafe D3D12_RT_FORMAT_ARRAY(DXGI_FORMAT* pFormats, uint NumFormats)
{
    Unsafe.SkipInit(out this);
    NumRenderTargets = NumFormats;
    Buffer.MemoryCopy(Unsafe.AsPointer(ref RTFormats), pFormats, sizeof(_RTFormats_e__FixedBuffer), sizeof(_RTFormats_e__FixedBuffer));
}

In my case this set the source DXGI_FORMAT to DXGI_FORMAT_UNKNOWN, and set an unrelated local variable to null...

Avoiding the constructor works as expected.

D3D12_RT_FORMAT_ARRAY renderTargetFormatArray = new();

renderTargetFormatArray.NumRenderTargets = 1;
renderTargetFormatArray.RTFormats[0]     = DXGI_FORMAT_R16G16B16A16_FLOAT;