Villacaleb / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

DX11 : DXGI error after saving backbuffer to file using Texture2D.ToFile or Ressource.SaveTextureToFile #856

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I have a DXGI error when I try to save the backbuffer into a file.
For example, with the simpleTriangle project, all works fine with the two 
following code :

...
context.Draw(3, 0);
swapChain.Present(0, PresentFlags.None);
Texture2D.ToFile(context, (Texture2D)renderTarget.Resource, 
ImageFileFormat.Png, "test_2.png");
...

or
...
context.Draw(3, 0);
swapChain.Present(0, PresentFlags.None);
Resource.SaveTextureToFile(context, renderTarget.Resource, ImageFileFormat.Png, 
"test_1.png");
...

but if i resize the RenderForm or even move it, there's a DXGIException in the 
form.UserResized at this line
swapChain.ResizeBuffers(2, 0, 0, fmt, SwapChainFlags.AllowModeSwitch);

even with the previous renderTarget.Dispose();

DXGI Error: Swapchain cannot be resized unless all outstanding buffer 
references have been released.

I can avoid that exception with the following code

Texture2D duplicate = Resource.FromSwapChain<Texture2D>(swapChain, 0);
                    context.CopyResource(renderTarget.Resource, duplicate);
                    Texture2D.ToFile(context, duplicate, ImageFileFormat.Png, "test_3.png");
                    duplicate.Dispose();

I use the SlimDX september 2011 release

Regards

Original issue reported on code.google.com by frederic...@gmail.com on 30 Dec 2011 at 9:54

GoogleCodeExporter commented 9 years ago
The Resource property is, in this case, returning an interface that was 
implicitly created (the backbuffer surface). This needs to be explicitly 
released.

There are workarounds we could put into place, but frankly at this point I 
think it might be best if you just add the few lines to make sure it gets 
disposed properly.

Original comment by Mike.Popoloski on 12 Mar 2012 at 11:35