IDXGISwapChain::ResizeBuffers() 0x887a0001 DXGI_ERROR_INVALID_CALL

2

When calling IDXGISwapChain::ResizeBuffer() the call fails and returns this error from the HRESULT 0x887a0001 otherwise known as DXGI_ERROR_INVALID_CALL.

What happens prior to this call is, I call ID3D11DeviceContext::ClearState() and release the ID3D11RenderTargetView and ID3D11DepthStencilView.

The above views are the only views bound to the the IDXGISwapChain.

I will post the code below to show everyone and if anyone can help me further with this problem it would be much appreciated:

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

Please help, if there is some way I can view what is bound to the swapchain at call time using the debugger that would be great.

Thanks, hoping for help :)

c++
resize
buffer
direct3d11
asked on Stack Overflow Feb 28, 2016 by Alice Fluff • edited Feb 28, 2016 by S.Spieker

1 Answer

0

The first parameter of the ResizeBuffers method cannot be 1 if you are using a front and back buffer. Either change the value to 2, or specify 0 to maintain the original value.

answered on Stack Overflow Feb 28, 2016 by Rakete1111

User contributions licensed under CC BY-SA 3.0