destroy directx device and swap chain

雨燕双飞 提交于 2019-12-11 11:12:55

问题


I am encountering a strange issue I think involves D3D11CreateDeviceAndSwapChain I can create the device and swap chain however when the application exits and ->destroy gets called on the swap chain, device, and device context a thread is still running. Commenting out this line the application terminates as expected.

featureLevel = D3D_FEATURE_LEVEL_11_0;
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

if(FAILED(result))
{
#ifdef _DEBUG
    log(logDEBUG) << "Error at D3D11CreateDeviceAndSwapChain";
#endif
    return false;
}
return true;

and the destruction:

if(m_swapChain)
{
    m_swapChain->SetFullscreenState(false, NULL);
}

if(m_device)
{
    m_device->Release();
}

if(m_deviceContext)
{
    m_deviceContext->Release();
}

if(m_swapChain)
{
    m_swapChain->Release();
}

I am fairly confident that the issue is coming from this, but I am not 100% sure. stepping through the code i see that each Release gets called correctly. (the application will close properly if the first block is commented out.)

Thanks for any insight regarding this issue.


回答1:


I am not entirely sure what I did, but I managed to get the issue to go away. I was cleaning up code in a different portion and all of a sudden everything started closing properly.

I have a feeling I wasn't setting up or closing the window correctly.




回答2:


Because swap chain hold a reference to the device context, and device context hold a reference to the device, the problem might be related to the order of the calls. Try releasing swap chain first, then - device context, and then device itself.



来源:https://stackoverflow.com/questions/12538287/destroy-directx-device-and-swap-chain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!