调用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;
        }
    }
}


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

谢谢,希望能有所帮助:)

最佳答案

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

07-26 01:24