IDXGISwapChain :: ResizeBuffers()0x887a0001 DXGI_ERROR_INVALID_CALL

时间:2016-02-28 15:42:57

标签: c++ resize buffer direct3d11

调用IDXGISwapChain::ResizeBuffer()时,调用失败并从HRESULT 0x887a0001返回此错误,也称为DXGI_ERROR_INVALID_CALL

此次通话之前会发生什么,我致电ID3D11DeviceContext::ClearState()并发布ID3D11RenderTargetViewID3D11DepthStencilView

以上观点是唯一与IDXGISwapChain绑定的观点。

我将发布以下代码以向所有人展示,如果有人能够帮助我进一步解决这个问题,我将不胜感激:

void SRNTY_API Direct3D11::D3D11ResizeBuffers(void)
{
    mResizing = true;

    RECT rect;
    GetWindowRect(mhWnd, &rect);
    mRenderTargetWidth = rect.right - rect.left;
    mRenderTargetHeight = rect.bottom - rect.top;

    if (gDXGI.GetSwapChain() != NULL)
    {
        assert(mD3D11DeviceContext);
        assert(mD3D11Device);
        assert(gDXGI.GetSwapChain());

        if (mD3D11DeviceContext)
            mD3D11DeviceContext->ClearState();

        if (mD3D11RenderTargetView)
            if (FAILED(result = mD3D11RenderTargetView->Release()))
            {
                SRNTY::gErrorHandler->AddError(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR21_D3D11ResizeBuffers),
                    SRNTY::ErrorHandler::ErrorHeaderSelect::EHS_ERROR);
            }

        if (mD3D11DepthStencilView)
            if (FAILED(result = mD3D11DepthStencilView->Release()))
            {
                SRNTY::gErrorHandler->AddError(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR22_D3D11ResizeBuffers),
                    SRNTY::ErrorHandler::ErrorHeaderSelect::EHS_ERROR);
            }

        if (FAILED(result = gDXGI.GetSwapChain()->ResizeBuffers(1, mRenderTargetWidth, mRenderTargetHeight,
            DXGI_FORMAT_R8G8B8A8_UNORM, 0)))   // the offending line
        {
            SRNTY::gErrorHandler->AddError(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR23_D3D11ResizeBuffers),
                SRNTY::ErrorHandler::ErrorHeaderSelect::EHS_ERROR);
        }

        if (FAILED(result = gDXGI.GetSwapChain()->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mD3D11RenderTargetView)))
        {
            SRNTY::gErrorHandler->AddError(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR24_D3D11ResizeBuffers),
                SRNTY::ErrorHandler::ErrorHeaderSelect::EHS_ERROR);
        }

        if (FAILED(result = gDXGI.GetSwapChain()->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mD3D11DepthStencilView)))
        {
            SRNTY::gErrorHandler->AddError(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR25_D3D11ResizeBuffers),
                SRNTY::ErrorHandler::ErrorHeaderSelect::EHS_ERROR);
        }

        D3D11_VIEWPORT viewport;
        ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

        viewport.TopLeftX = 0;
        viewport.TopLeftY = 0;
        viewport.Width = mRenderTargetWidth;
        viewport.Height = mRenderTargetHeight;
        viewport.MinDepth = 0.0f;
        viewport.MaxDepth = 1.0f;

        if ((mD3D11DeviceContext != NULL) && (mD3D11RenderTargetView != NULL) && (mD3D11DepthStencilView != NULL))
        {
            mD3D11DeviceContext->OMSetRenderTargets(1, &mD3D11RenderTargetView, mD3D11DepthStencilView);
            mD3D11DeviceContext->RSSetViewports(1, &viewport);
            mResizing = false;
            return;
        }
        else
        {
            SRNTY::gErrorHandler->AddError(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR26_D3D11ResizeBuffers),
                SRNTY::ErrorHandler::ErrorHeaderSelect::EHS_ERROR);
            SRNTY::gErrorHandler->EmergencyShutDown();
            ERROR(gErrors->ERRORCODE(_ERROR::ERRORCODES::ERR26_D3D11ResizeBuffers).c_str());
            return;
        }           
    }
}

请帮助,如果有某种方法,我可以使用调试器在调用时查看绑定到交换链的内容。

谢谢,希望得到帮助:)

1 个答案:

答案 0 :(得分:0)

如果使用前后缓冲区,则ResizeBuffers方法的第一个参数不能为1。将值更改为2,或指定0以保持原始值。