I have a Direct2D render target created with ID2D1Factory::CreateDxgiSurfaceRenderTarget. When I receive a WM_SIZE message, I try to resize the corresponding swap chain by calling IDXGISwapChain::ResizeBuffers, but it fails with DXGI_ERROR_INVALID_CALL (0x887a0001). I believe it's because of the following stated by the ResizeBuffers documentation:
You can't resize a swap chain unless you release all outstanding references to its back buffers. You must release all of its direct and indirect references on the back buffers in order for ResizeBuffers to succeed.
Direct references are held by the application after it calls AddRef on a resource.
Indirect references are held by views to a resource, binding a view of the resource to a device context, a command list that used the resource, a command list that used a view to that resource, a command list that executed another command list that used the resource, and so on.
I would assume that a Direct2D render target created by ID2D1RenderTarget::CreateDxgiSurfaceRenderTarget is one such indirect reference. But I can't imagine that I should recreate the render target everytime the window is resized, so what should I do?
Nevermind, apparently the render target does need to be re-created everytime the window is resized, as explained here.
User contributions licensed under CC BY-SA 3.0