0

我有一个简单的 DirectX 程序,当我最小化然后取消最小化时会崩溃。

这些是我介绍的事件案例:

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

调整大小大致为:

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

当我取消最小化时,代码在尝试设置后台缓冲区时死亡。这是传递值的行:
hr=swapChain->ResizeBuffers(3, 640, 480, DXGI_FORMAT_UNKNOWN, 0);
ResizeBuffers() 返回错误 0x887a0005

后台缓冲区代码:

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

任何人都知道为什么后台缓冲区呕吐?

4

1 回答 1

1

只是剩下的,你应该更好地在 WM_SIZE 中单独处理最小化消息(SIZE_MINIMIZED),如果窗口被最小化,停止渲染并将 CPU 时间让给其他程序。

于 2012-11-08T02:07:08.977 回答