please examine a code snippet below:
var form = new Form();
form.Width = 640;
form.Height = 480;
var pp = new PresentParameters();
pp.DeviceWindowHandle = form.Handle;
pp.BackBufferWidth = form.Width;
pp.BackBufferHeight = form.Height;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, pp);
var swapChain = new SwapChain(device, pp);
Surface surface = swapChain.GetBackBuffer(0);
swapChain.Dispose();
Why the surface resource is still alive even after disposing swap chain? My expectation is that the surface is a part of the swapChain and it should be disposed after the swap chain has been disposed..
Is this pseudo code correct for case with multiple swap chains, i mean is it normal situation when the back buffer surface disposes in each frame?
Device m_device;
void RenderFrame(SwapChain swapChain)
{
Surface surface = swapChain.GetBackBuffer(0);
m_device.SetRenderTarget(0, surface);
You can use PIX to determine what is happening. I've seen this before but with GDNet. Microsoft says you have to switch to windowed mode before disposing of the swap chain. SetFullscreenState(false, NULL);
The only other thing I can think of is a garbage collection issue.
In your first code dump you acquire the Surface (Surface surface = swapChain.GetBackBuffer(0);) but don't dispose of it. In COM, whenever you acquire ownership of a handle to an object the reference count is incremented. Now, SlimDX does some trickery in the background to make this easier for you to manage, but in general if you call "GetSomething" in slimdx then you should call "Dispose" on the reference returned when you're done with it.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
What is interesting that the resource <0x08CB6610> is still alive even after call
30 <0x08CB6610> IDirect3DSurface9::Release() 31753470 . So as i see surface.Dispose() actually doesn't free the surface.
Dispose calls release. That does not mean that it will free the object, just that if the REFERENCE COUNT is 0 it will free the object.
The back buffer is used by the swap chain. The swap chain maintains a reference to the back buffer. This is just one of many possible references to the back buffer that might exist.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.