[quote name='Tape_Worm' timestamp='1318900097' post='4873706']
[quote name='jameszhao00' timestamp='1318880299' post='4873597']
Hmm.
Try calling the following function repeatedly around your mode switching code
int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}
and see if the reported ref counts matches your expectations / agrees with the non-broken situation.
So I tried out your code to check the refcount. When I create the D3DDevice, it's got a count of 1 (naturally), and just before I destroy the device, it's got a count of 2, which is kind of odd. I only have a call to CreateSwapChain and the code to create the D3DDevice, so something's amiss. It claims the extra reference is an external reference, but I really have absolutely nothing else in here that's adding to the ref count. It just makes no sense.
Thanks for your help.
[/quote]
Locating where it broke:
Go into PIX. Select "A replayable Direct3D call stream". Run your app. Break your app. Then in PIX, find (binary search ) the exact call site where "D3D11 Device" (in the Objects window) has unexpected "App Refs".
Note: To actually view the app refs, for some reason you have to a) select a random frame b) select render. Make sure you're in the Mesh or Render tab when selecting different calls (to force refresh)
[/quote]
Thanks for that. I've always had a hell of a time getting PIX to behave itself with .NET apps, and it was a little better tonight.
So, here's what my logging (and your ref counter code) told me before it destroyed the ID3D11Device:
[10/17/2011 08:24:04 PM] D3D Device Ref Count #: 3
So, according to that, there were 3 references to the device.
Then I poured through the calls in PIX, and I found a very different story. The AppRefs never went above 2, and always fell back to 1 (until the final Dispose call on the device object, which then said there were no more references). But, when I turn on the return result I can see in each AddRef/Release from the reference counting code that the values are higher. In some cases, it returns as high as 5. I understand these could be internal references, and as such, and my releasing of my only reference to the ID3D11Device is only going to decrement the count by 1, leaving those other references.