Reputation: 61
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.
Upvotes: 1
Views: 3302
Reputation: 61
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.
Upvotes: 1
Reputation: 551
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.
Upvotes: 0