Error 0x887A0001 from SharpDX ResizeBuffers on Resize event

1

I tried to make this sample resizable.

I added only this event handler on Resize, but I get error 0x887A0001. What can I do?

static void form_Resize(object sender, EventArgs e)
{
    backBuffer.Dispose();
    renderView.Dispose();
    device.Dispose();
    swapChain.ResizeBuffers(1, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.AllowModeSwitch);
}
c#
resize
direct2d
sharpdx
asked on Stack Overflow Mar 13, 2015 by GorillaApe • edited Apr 9, 2015 by catflier

1 Answer

4

Since you do not release backBuffer and all associated resources, you'll have the following error in debug mode:

DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]

To make sure that everything is released and recreated properly, you can attach the following code between stopwatch.Start() (Line 88) and RenderLoop.Run(...) (Line 91):

form.ResizeEnd += (sender, args) =>
{
    device.ImmediateContext.ClearState();
    d2dRenderTarget.Dispose();
    backBuffer.Dispose();
    renderView.Dispose();
    surface.Dispose();
    swapChain.ResizeBuffers(1, 0, 0, Format.Unknown, SwapChainFlags.AllowModeSwitch);
    backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
    renderView = new RenderTargetView(device, backBuffer);
    surface = backBuffer.QueryInterface<Surface>();
    d2dRenderTarget = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
};

device.ImmediateContext.ClearState() is optional (in your case, using Direct2D, it's not needed, but generally it's a good idea to add it to also make sure that render target is not bound to the context anymore, since CLR will only dispose it on the need command buffer flush.

answered on Stack Overflow Apr 9, 2015 by catflier • edited Jul 2, 2018 by Davide Cannizzo

User contributions licensed under CC BY-SA 3.0