DirectX Crash On Minimize

0

I have a simple DirectX program that crashes when I minimize & then unminimize.

These are the event cases I cover:

case WM_SIZING:
case WM_SIZE:
    if(engine.isReady()) engine.resizeDevice();
    if(engine.isReady()) engine.draw();
    break;

The resize is roughly:

deviceContext->OMSetRenderTargets(0, NULL, NULL);
    ...
deviceInterface->CreateRenderTargetView( ... );
    ...
deviceContext->RSSetViewports(1, &vp);
    ...
deviceContext->OMSetRenderTargets(1, &renderTargetInterface, NULL);

When I unminimize, the code dies while trying to set the back buffer. This is the line with the values passed:
hr=swapChain->ResizeBuffers(3, 640, 480, DXGI_FORMAT_UNKNOWN, 0);
ResizeBuffers() returns error 0x887a0005

Back buffer code:

HRESULT _setBackBuffer(const SettingsVD &settings){
    HRESULT hr;

    hr=swapChain->ResizeBuffers(settings.bufferCount, settings.width, settings.height, DXGI_FORMAT_UNKNOWN, 0);
    if(FAILED(hr)) return hr; // Dies here when UNminimizing

    ID3D11Texture2D* backBuffer=NULL;
    hr=swapChain->GetBuffer(0, __uuidof(backBuffer), (LPVOID*)&backBuffer);
    if(FAILED(hr)) return hr;

    hr=deviceInterface->CreateRenderTargetView(backBuffer, NULL, &renderTargetInterface);
    if(FAILED(hr)) return hr;

    release(backBuffer);

    return hr;
}

Anyone know why the back buffer is barfing?

c++
windows
resize
directx
directx-11
asked on Stack Overflow Nov 7, 2012 by RandomClown • edited May 23, 2017 by Community

1 Answer

1

Just a remainder, you should better handle the minimize message(SIZE_MINIMIZED) separately in WM_SIZE, if the windows was minimized, stop rendering and yield the CPU time to other programs.

answered on Stack Overflow Nov 8, 2012 by zdd

User contributions licensed under CC BY-SA 3.0