Skip to content

Commit

Permalink
Stop crash on window snap by preventing torn device resources state (#…
Browse files Browse the repository at this point in the history
…1768)

* Stop crash on window snap by preventing torn device resources state when quick on-the-fly resizing operations happen. #1572

(cherry picked from commit d848507)
  • Loading branch information
miniksa authored and DHowett committed Jul 2, 2019
1 parent 0f3d25c commit d624070
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/renderer/dx/DxRenderer.cpp
Expand Up @@ -690,10 +690,24 @@ void DxEngine::_InvalidOr(RECT rc) noexcept
else if (_displaySizePixels.cy != clientSize.cy ||
_displaySizePixels.cx != clientSize.cx)
{
// OK, we're going to play a dangerous game here for the sake of optimizing resize
// First, set up a complete clear of all device resources if something goes terribly wrong.
auto resetDeviceResourcesOnFailure = wil::scope_exit([&] {
_ReleaseDeviceResources();
});

// Now let go of a few of the device resources that get in the way of resizing buffers in the swap chain
_dxgiSurface.Reset();
_d2dRenderTarget.Reset();
_dxgiSwapChain->ResizeBuffers(2, clientSize.cx, clientSize.cy, DXGI_FORMAT_B8G8R8A8_UNORM, 0);

// Change the buffer size and recreate the render target (and surface)
RETURN_IF_FAILED(_dxgiSwapChain->ResizeBuffers(2, clientSize.cx, clientSize.cy, DXGI_FORMAT_B8G8R8A8_UNORM, 0));
RETURN_IF_FAILED(_PrepareRenderTarget());

// OK we made it past the parts that can cause errors. We can release our failure handler.
resetDeviceResourcesOnFailure.release();

// And persist the new size.
_displaySizePixels = clientSize;
}

Expand Down

0 comments on commit d624070

Please sign in to comment.