Direct3D11 - Access violation executing location xxx on CreateSwapChainForCoreWindow

1

I am learning C++ and Direct3D11/Direct2D (on top of UWP) for fun, but am struggling getting my little test program to run. It throws an access violation (see below for exact exception) when I call CreateSwapChainForCoreWindow.

I used the D3D Device for other calls and they worked so I don't think that is the issue. The swap chain description is relatively straight-forward and the swap chain itself will be set in the call. So, I assume that the exception is because I am passing an incorrect pointer to the window but I can't solve it.

Exception:

Exception thrown at 0x00007FF8FE44F4E0 (Windows.UI.dll) in UWP D2D example v3.exe: 0xC0000005: Access violation executing location 0x00007FF8FE44F4E0.

Code snippet (https://github.com/cwebb95/Direct2D_cppwinrt):

        ComPtr<IDXGISwapChain1> swapChain = nullptr;
        DX::ThrowIfFailed(dxgiFactory->CreateSwapChainForCoreWindow(m_d3dDevice.Get(),
                                        reinterpret_cast<IUnknown*>(&CoreWindow::GetForCurrentThread()),
                                        &swapChainDescription,
                                        NULL,    
                                        &swapChain));
c++
uwp
direct2d
direct3d11
asked on Stack Overflow Oct 22, 2020 by Clayton • edited Oct 23, 2020 by Clayton

1 Answer

1

I was able to solve my problem by changing the second parameter to:

static_cast<::IUnknown*>(winrt::get_abi(CoreWindow::GetForCurrentThread()))

from:

reinterpret_cast<IUnknown*>(&CoreWindow::GetForCurrentThread())

I am not knowledge enough yet to know why that fixed the problem, but I will research and hopefully figure it out (any leads on that question would be much appreciated).

answered on Stack Overflow Oct 23, 2020 by Clayton

User contributions licensed under CC BY-SA 3.0