This feels extremely off, but I just can't seem to track the issue down so I thought I'd ask in case someone else has experienced something similar.
So I'm writing a game engine in C++ using DX11 for rendering. Its going rather well for the moment and everything works just as intended when I build it as an executable. However, as a side project I'm also wrapping the engine functionality into a dynamic link library so that it may be used from other languages as well. Now this is also working... for the most part. For some reason that has me dumbfounded the host application using the dll ends up in a deadlock upon calling DLLMain with the DLL_PROCESS_DETACH reason. I've tracked the issue down to happen inside my final release call that results in my ID3D11Device getting a reference count of 0, so it most likely happens as the device is destroyed. Unfortunately there is no debugging information available that lets me see exactly where it all goes sour in there, except for that control goes into the final Release() call and never comes back out.
I have logged the refcounts for the device, device context, swapchain, etc. and they are released in exactly the same manner in DLL and executable build alike, yet the DLL version gets stuck while the executable happily terminates without as much as a sniffle from the DX debug layer or anything that would hint at hidden errors. I've gone through my code two times searching for lingering buffers that may be dependent on the device (however were that really the case it should maintain its own reference and thus prevent it from being destroyed before the buffer / whatever resource is).
Code and reference counts:
// pSwapChain has 1 reference, pDevCon 1 and pDev 3 here if(pSwapChain) pSwapChain->Release(); // pSwapChain has 0 references, pDevCon 1 and pDev 2 after this line if(pDevCon) pDevCon->Release(); // pSwapChain is unreferenced, pDevice context hits 0 references and pDev has 1 remaining reference if(pDev) pDev->Release(); // 0 references for all three resources in executable build; control never returns from this call in dll build
So for my questions... is there any way to debug inside the ID3DDevice::Release() / ID3DDevice::dtor() bodies to see what's really happening? Is this code even open source / otherwise available for reading? I'm guessing not. Secondly, is this a known issue that can arise and, if so, what causes it? I've tried searching a good deal for it but have so far been unable to find anything relevant.
Thanks for any ideas,
Edited by Husbjörn, 25 April 2014 - 06:14 PM.