Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualBacterius

Posted 31 October 2013 - 03:42 PM

I ran into the same problem a few days ago. As unbird mentions you must dispose of any device resource you acquire a reference to by calling Get* functions. One thing to remember is that Dispose() does not destroy the resource, it simply decreases the reference count and invalidates said reference, the resource itself is only destroyed when it hits zero. So in theory this should work:

using (Resource resource = CubeMapSRV.Resource)
{
    resource.DebugName = "sky cubemap";
}

In practice, I prefer to avoid messing around with reference counters and instead created a helper class which stores a resource and provides non-reference-counted access to SRV's, RTV's, UAV's, ... By the way, this problem also applies to ImmediateContext and a bunch of other stuff, and you don't need to set variables to null after disposing them. I think the underlying issue is that the C# memory management model does not quite map to how DirectX works, so you need to be a bit more careful with what you do to avoid making incorrect assumptions.


#1Bacterius

Posted 31 October 2013 - 03:40 PM

I ran into the same problem a few days ago. As unbird mentions you must dispose of any device resource you acquire a reference to by calling Get* functions. One thing to remember is that Dispose() does not destroy the resource, it simply decreases the reference count and invalidates said reference, the resource itself is only destroyed when it hits zero. So in theory this should work:

using (Resource resource = CubeMapSRV.Resource)
{
    resource.DebugName = "sky cubemap";
}

In practice, I prefer to avoid messing around with reference counters and instead created a helper class which stores a resource and provides non-reference-counted access to SRV's, RTV's, UAV's, ... By the way, this problem also applies to ImmediateContext and a bunch of other stuff, and you don't need to set variables to null after disposing them. I think the underlying issue is that the C# memory management model does not quite map to how DirectX works, so you need to be a bit more careful with what you do to avoid making incorrect assumptions.


PARTNERS