zeux/volk

vkDestroyDevice & vkDestroyInstance fail at dll unloading

fynv opened this issue · 4 comments

fynv commented

Not sure if this is something that can be fixed in volk.

What I'm trying to do is something like:

MyContext::~MyContext()
{
	vkDestroyDevice(m_device, nullptr);
	vkDestroyInstance(m_instance, nullptr);
}
static MyContext s_context;

I expected that the destructor of s_context would be called at process exit time, so that I can do some clean up there. This works fine when the code is built into an exe file.
However, when I use the code above in a dll module, sometimes the vkDestroyxx commands will fail, which I guess is because vulkan-1.dll is unloaded earlier than my dll.
Is there anything I can do to fix this?

Thanks.

fynv commented

Sorry, seems I made a mistake, because vkDestroyDevice & vkDestroyInstance are the only 2 vk functions that don't work. Changing title. Now it looks more likely there's something wrong in my own code.

zeux commented

Can you confirm that the issue is actually the DLL unloading? You should be able to see the DLL unload events in the debugger output. In general I'd expect vulkan-1.dll to not unload up until the process terminates (because volk doesn't have a deinitialization procedure, it never frees the library handle).

I've never used Vulkan function from DLL loader though, there might be restrictions that the system imposes in terms of functions that are valid to call...

fynv commented

Yes, you are right, vulkan-1.dll is not unloaded. The issue is that when unloading my own dll, vkDestroyDevice & vkDestroyInstance fails during destructing a static object (in my own dll).
The other vkDestroyxx functions work at the same moment, such as vkDestroyBuffer, vkFreeMemory. Seems that the function-pointers vkDestroyDevice, vkDestroyInstance are valid too. As you said, maybe I just should not call these 2 functions at that time. While I'm still debugging it, we may close this if you would like. Thanks.

fynv commented

Closing. Not a volk issue.