From 92520c1d9bffedcd558e8076691bc348285320df Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 21 Oct 2024 00:37:09 -0700 Subject: [PATCH] Improved D3D12 handling of unrecoverable device loss --- src/render/direct3d12/SDL_render_d3d12.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c index ec3cfe9dbbbfa..42a02f5e9a858 100644 --- a/src/render/direct3d12/SDL_render_d3d12.c +++ b/src/render/direct3d12/SDL_render_d3d12.c @@ -1338,12 +1338,14 @@ D3D12_HandleDeviceLost(SDL_Renderer *renderer) result = D3D12_CreateDeviceResources(renderer); if (FAILED(result)) { // D3D12_CreateDeviceResources will set the SDL error + D3D12_ReleaseAll(renderer); return result; } result = D3D12_UpdateForWindowSizeChange(renderer); if (FAILED(result)) { // D3D12_UpdateForWindowSizeChange will set the SDL error + D3D12_ReleaseAll(renderer); return result; } @@ -2830,6 +2832,10 @@ static bool D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; const int viewportRotation = D3D12_GetRotationForCurrentRenderTarget(renderer); + if (!rendererData->d3dDevice) { + return SDL_SetError("Device lost and couldn't be recovered"); + } + if (rendererData->pixelSizeChanged) { D3D12_UpdateForWindowSizeChange(renderer); rendererData->pixelSizeChanged = false; @@ -3113,6 +3119,10 @@ static bool D3D12_RenderPresent(SDL_Renderer *renderer) D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal; HRESULT result; + if (!data->d3dDevice) { + return SDL_SetError("Device lost and couldn't be recovered"); + } + // Transition the render target to present state D3D12_TransitionResource(data, data->renderTargets[data->currentBackBufferIndex],