简体   繁体   中英

Direct3D11 - Access violation executing location xxx on CreateSwapChainForCoreWindow

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));

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM