DXGI错误:IDXGISwapChain :: ResizeBuffers:交换链无法调整大小,除非所有未完成的缓冲区引用都已释放

时间:2019-02-25 11:57:08

标签: c++ gdi+ directx-11 direct3d11 dxgi

当我创建一个新的渲染窗口时,我已经调整了缓冲区的大小。我遵循了this postthis post来调整缓冲区的大小。但是下面的错误不断出现。任何人都经历过此错误?我需要确切地知道应该在哪里进行修复。

/* 1. Clear render targets from device context */
// Clear the previous window size specific context.
ID3D11RenderTargetView* nullViews[] = { nullptr };
m_context->OMSetRenderTargets(_countof(nullViews), nullViews, nullptr);
/* 2. Release Rendering Target */
m_renderTargetView = nullptr;
m_depthStencilView = nullptr;

m_context->Flush();

// If the swap chain already exists, resize it.
if (m_swapChain != nullptr)
{
    /* 3. Resize buffer */
    HRESULT hr = m_swapChain->ResizeBuffers(
        m_bufferCount, /* here buffer count is 1 */
        static_cast<UINT>(m_renderTargetSize.width),
        static_cast<UINT>(m_renderTargetSize.height),
        DXGI_FORMAT_B8G8R8A8_UNORM,
        m_gdiCompatible ? DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE : 0 /* GDI compatible is false*/
    );
    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
    {
        // If the device was removed for any reason, a new device and swap chain will need to be created.
        CreateSwapChain(m_device);
    }
    else
    {
        THROW_PE(hr);
    }
}
else // Otherwise, create a new one.
{
    CreateSwapChain(m_device);
}

/* 4. Reset the buffer as target view */
IDXGISurfacePtr dxgiBackBufferSurface;
IF_FAILED_THROW_HR(m_swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBufferSurface)));
m_d2dRenderer->CreateRenderTargetResources(dxgiBackBufferSurface);


// Obtain the back buffer for this window which will be the final 3D render target.
ID3D11Texture2DPtr backBuffer;
IF_FAILED_THROW_HR(m_swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)));

// Create a descriptor for the RenderTargetView.
CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc(D3D11_RTV_DIMENSION_TEXTURE2DARRAY, DXGI_FORMAT_B8G8R8A8_UNORM, 0, 0, 1);

// Create a view interface on the render target to use on bind for mono or left eye view.
IF_FAILED_THROW_HR(m_device->CreateRenderTargetView(backBuffer, &renderTargetViewDesc, &m_renderTargetView));

     ------------

// Create a descriptor for the depth/stencil buffer.
CD3D11_TEXTURE2D_DESC depthBufferDesc(DXGI_FORMAT_D24_UNORM_S8_UINT, static_cast<UINT>(m_renderTargetSize.width), static_cast<UINT>(m_renderTargetSize.height),
    1, 1, D3D11_BIND_DEPTH_STENCIL);

// Allocate a 2-D surface as the depth/stencil buffer.
ID3D11Texture2DPtr depthStencilBuffer;
IF_FAILED_THROW_HR(m_device->CreateTexture2D(&depthBufferDesc, nullptr, &depthStencilBuffer));

// Create a DepthStencil view on this surface to use on bind.
CD3D11_DEPTH_STENCIL_VIEW_DESC viewDesc = CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D, DXGI_FORMAT_D24_UNORM_S8_UINT);
IF_FAILED_THROW_HR(m_device->CreateDepthStencilView(depthStencilBuffer, &viewDesc, &m_depthStencilView));

/* 5. Set the new render target*/
m_context->OMSetRenderTargets(1, &m_renderTargetView.GetInterfacePtr(), m_depthStencilView);

/* 6. Reset view port */
UpdateViewport(D2D1::RectF(0.0f, 0.0f, m_renderTargetSize.width, m_renderTargetSize.height));
  

DXGI错误:IDXGISwapChain :: ResizeBuffers:除非已释放所有未完成的缓冲区引用,否则无法调整交换链的大小。 [其他错误#19:]

0 个答案:

没有答案