SDL: Fixed resource leak and crash at exit in the D3D11 renderer (116a5)

From 116a5344ff4e8b8166eac2db540cd6578b4ba02e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 3 Jul 2023 17:39:29 -0700
Subject: [PATCH] Fixed resource leak and crash at exit in the D3D11 renderer

Also, for some reason ID3D11DeviceContext_OMGetRenderTargets() was failing in the second read pixels call in the "testautomation --filter render_testViewport" test.

We already know the target view, so just use that.

(cherry picked from commit 619f65af0c390dd10bc0e6bf9dc1227e7ecee54d)
(cherry picked from commit 61808b03b5c5e2efe9b37d6c699c133d47448ea9)
 src/render/direct3d11/SDL_render_d3d11.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 06d66214d49d..2d8ee3c0a0a2 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -2143,7 +2143,7 @@ static int D3D11_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
     D3D11_BOX srcBox;
     D3D11_MAPPED_SUBRESOURCE textureMemory;
-    ID3D11DeviceContext_OMGetRenderTargets(data->d3dContext, 1, &renderTargetView, NULL);
+    renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
     if (renderTargetView == NULL) {
         SDL_SetError("%s, ID3D11DeviceContext::OMGetRenderTargets failed", __FUNCTION__);
         goto done;