Hi,
I am trying to resize the window. I managed it before in another project (dx11 this is dx11.1) but I just can't seem to find the outstanding reference that is needed to be released before resizing the swap chain. I get the error in the output window:
DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]
DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]
I have already seen the following links that cover this in a little detail:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb205075%28v=vs.85%29.aspx#Handling_Window_Resizing and Gamedev_Duplicate_Post_Here and
In the last one Erik Rufelt explains in post #17 that all references to the backbuffer must be released. The only place that I would have had a reference would have been the Direct2D class (CD2DObj), for drawing a textured quad, but I cut it out and now I'm just displaying a coloured screen. Here is the ::OnResize code that is called at the end of ::InitDirect3D and also in MsgProc's WM_SIZE handler:
Additional: On start up the this is called but does not seem to get released as I check with the swapchain's addref/release pairs periodically. Also I am creating the swapchain with backbuffer count of 1.
try
{
assert(m_spD3DImmediateContext);
assert(m_spD3DDevice);
assert(m_spSwapChain);
//ReleaseCOM(m_pRenderTargetView);
//ReleaseCOM(m_pDepthStencilView);
//ReleaseCOM(m_spDepthStencilBuffer);
//m_spRenderTargetView.Reset();
//m_spDepthStencilView.Reset();
//m_spDepthStencilBuffer.Reset();
//m_spDepthDisabledStencilState.Reset();
// This is used to monitor the reference count
auto Myref = m_spSwapChain->AddRef();
Myref = m_spSwapChain->Release();
ULONG RefCount = 0;
//if (m_spDepthEnabledStencilState)
// RefCount = m_spDepthEnabledStencilState->Release();
//assert(RefCount == 0); // Fails = 1
//if (m_spDepthDisabledStencilState)
// RefCount = m_spDepthDisabledStencilState->Release();
//assert(RefCount == 0);
m_spD3DImmediateContext->OMSetRenderTargets(0, 0, 0);
if (m_spDepthStencilView)
RefCount = m_spDepthStencilView->Release();
assert(RefCount == 0);
if (m_spDepthStencilBuffer)
RefCount = m_spDepthStencilBuffer->Release();
assert(RefCount == 0);
if (m_spRenderTargetView)
RefCount = m_spRenderTargetView->Release();
assert(RefCount == 0);
//m_spRenderTargetView.Reset();
//m_spDepthStencilView.Reset();
//m_spDepthStencilBuffer.Reset();
//m_spDepthDisabledStencilState.Reset();
//assert(m_spRenderTargetView == nullptr);
//assert(m_spDepthStencilView == nullptr);
//assert(m_spDepthStencilBuffer == nullptr);
//assert(m_spDepthDisabledStencilState == nullptr);
Myref = m_spSwapChain->AddRef();
Myref = m_spSwapChain->Release();
// Resize the swap chain and recreate the render target view.
COMERR(m_spSwapChain->ResizeBuffers(1, m_iClientWidth, m_iClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0),
"CD3DObject::OnResize() SwapChain Could not resize.");
ID3D11Texture2D* pBackBuffer;
COMERR(m_spSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer)),
"CD3DObject::OnResize() SwapChain could not get backbuffer.");
COMERR(m_spD3DDevice->CreateRenderTargetView(pBackBuffer, 0, m_spRenderTargetView.GetAddressOf()),
"CD3DObject::OnResize() Could not re-create render target view.");
Myref = m_spSwapChain->AddRef();
Myref = m_spSwapChain->Release();
//ReleaseCOM(pBackBuffer);
RefCount = pBackBuffer->Release();
Myref = m_spSwapChain->AddRef();
Myref = m_spSwapChain->Release();