SharpDX UWP Swapchain null reference upon Present
See the question and my original answer on StackOverflowIn your code you create the swapchain like this:
using swapChain = new SwapChain1(factory, dxgiDevice, ref swapChainDesc);
{
// do something
}
Which means it will get disposed as soon as you get out of the scope. When you call RenderFrame
, the swapChain
object itself is not null, because it's a .NET wrapper over the native thing, but it's underlying NativePointer
is, and you get a NullReferenceException
in SharpDX code "below".
Just keep the DirectX objects you need alive, like:
swapChain = new SwapChain1(factory, dxgiDevice, ref swapChainDesc);
And you should event store most of these "living" objects (device, swapchain, back buffer, etc.) stored in a member variable (dispose them only when closing the service code). On the contrary, you can generally release intermediate objects like factories as soon as you've finished using them (like what's done in today in your code).