diff --git a/src/Veldrid/D3D11/D3D11Swapchain.cs b/src/Veldrid/D3D11/D3D11Swapchain.cs index 74fce35f4..bc7137f9c 100644 --- a/src/Veldrid/D3D11/D3D11Swapchain.cs +++ b/src/Veldrid/D3D11/D3D11Swapchain.cs @@ -234,6 +234,8 @@ private void recreateSwapchain() Resize(_width, _height); } + private ID3D11Texture2D backBufferTexture; + public override void Resize(uint width, uint height) { _width = width; @@ -259,6 +261,7 @@ public override void Resize(uint width, uint height) _depthTexture.Dispose(); } + backBufferTexture.Dispose(); _framebuffer.Dispose(); } @@ -270,29 +273,28 @@ public override void Resize(uint width, uint height) } // Get the backbuffer from the swapchain - using (ID3D11Texture2D backBufferTexture = _dxgiSwapChain.GetBuffer(0)) + backBufferTexture = _dxgiSwapChain.GetBuffer(0); + + if (_depthFormat != null) { - if (_depthFormat != null) - { - TextureDescription depthDesc = new TextureDescription( - actualWidth, actualHeight, 1, 1, 1, - _depthFormat.Value, - TextureUsage.DepthStencil, - TextureType.Texture2D); - _depthTexture = new D3D11Texture(_gd.Device, ref depthDesc); - } + TextureDescription depthDesc = new TextureDescription( + actualWidth, actualHeight, 1, 1, 1, + _depthFormat.Value, + TextureUsage.DepthStencil, + TextureType.Texture2D); + _depthTexture = new D3D11Texture(_gd.Device, ref depthDesc); + } - D3D11Texture backBufferVdTexture = new D3D11Texture( - backBufferTexture, - TextureType.Texture2D, - D3D11Formats.ToVdFormat(_colorFormat)); + D3D11Texture backBufferVdTexture = new D3D11Texture( + backBufferTexture, + TextureType.Texture2D, + D3D11Formats.ToVdFormat(_colorFormat)); - FramebufferDescription desc = new FramebufferDescription(_depthTexture, backBufferVdTexture); - _framebuffer = new D3D11Framebuffer(_gd.Device, ref desc) - { - Swapchain = this - }; - } + FramebufferDescription desc = new FramebufferDescription(_depthTexture, backBufferVdTexture); + _framebuffer = new D3D11Framebuffer(_gd.Device, ref desc) + { + Swapchain = this + }; } public void WaitForNextFrameReady()