zeux/volk

Loading of `vkDestroyInstance` failed: Access violation writing location

achalpandeyy opened this issue · 5 comments

Capture

However, if I try to load it into a temporary variable (vkDestroyInstance_another) on the line https://github.com/zeux/volk/blob/master/volk.c#L153, like:

// vkDestroyInstance = (PFN_vkDestroyInstance)load(context, "vkDestroyInstance");
PFN_vkDestroyInstance vkDestroyInstance_another = (PFN_vkDestroyInstance)load(context, "vkDestroyInstance");

it seems to work and consequently vkDestroyInstance_another seems to be a pointer into vulkan-1.dll

Call stack:

helloworld_d.exe!volkGenLoadInstance(void * context, void(*)()(*)(void *, const char *) load) Line 153	C
helloworld_d.exe!volkLoadInstance(VkInstance_T * instance) Line 104	C
helloworld_d.exe!nbl::video::CVulkanConnection::CVulkanConnection(unsigned int appVer, const char * appName, const nbl::video::SDebugCallback & dbgCb) Line 33	C++
helloworld_d.exe!nbl::core::make_smart_refctd_ptr<nbl::video::CVulkanConnection,unsigned int &,char const * &,nbl::video::SDebugCallback const &>(unsigned int & <args_0>, const char * & <args_1>, const nbl::video::SDebugCallback & <args_2>) Line 333	C++
helloworld_d.exe!nbl::video::createVulkanConnection(unsigned int appVer, const char * appName, const nbl::video::SDebugCallback & dbgCb) Line 10	C++
helloworld_d.exe!nbl::video::IAPIConnection::create(nbl::video::E_API_TYPE apiType, unsigned int appVer, const char * appName, const nbl::video::SDebugCallback & dbgCb) Line 27	C++
helloworld_d.exe!main() Line 177	C++
[External Code]	
zeux commented

This doesn't make much sense to me. Could you show the disassembly at the point where the access violation happens (+-10 lines from current instruction) as well as the contents of the register window?

Sure. But please note that after I did a complete rebuild of my project it started crashing on https://github.com/zeux/volk/blob/master/volk.c#L138
Capture

static void volkGenLoadLoader(void* context, PFN_vkVoidFunction (*load)(void*, const char*))
{
00007FF657DB9820  mov         qword ptr [rsp+10h],rdx  
00007FF657DB9825  mov         qword ptr [rsp+8],rcx  
00007FF657DB982A  push        rdi  
00007FF657DB982B  sub         rsp,20h  
00007FF657DB982F  mov         rdi,rsp  
00007FF657DB9832  mov         ecx,8  
00007FF657DB9837  mov         eax,0CCCCCCCCh  
00007FF657DB983C  rep stos    dword ptr [rdi]  
00007FF657DB983E  mov         rcx,qword ptr [context]  
	/* VOLK_GENERATE_LOAD_LOADER */
#if defined(VK_VERSION_1_0)
	vkCreateInstance = (PFN_vkCreateInstance)load(context, "vkCreateInstance");
00007FF657DB9843  lea         rdx,[known_ext_strs+2B8h (07FF658652018h)]  
00007FF657DB984A  mov         rcx,qword ptr [context]  
00007FF657DB984F  call        qword ptr [load]  
00007FF657DB9853  mov         qword ptr [vkCreateInstance (07FF656E7FEEAh)],rax  
	vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties)load(context, "vkEnumerateInstanceExtensionProperties");
00007FF657DB985A  lea         rdx,[known_ext_strs+2D0h (07FF658652030h)]  
00007FF657DB9861  mov         rcx,qword ptr [context]  
00007FF657DB9866  call        qword ptr [load]  
00007FF657DB986A  mov         qword ptr [vkEnumerateInstanceExtensionProperties (07FF6586AD880h)],rax  
	vkEnumerateInstanceLayerProperties = (PFN_vkEnumerateInstanceLayerProperties)load(context, "vkEnumerateInstanceLayerProperties");
00007FF657DB9871  lea         rdx,[known_ext_strs+2F8h (07FF658652058h)]  
00007FF657DB9878  mov         rcx,qword ptr [context]  
00007FF657DB987D  call        qword ptr [load]  
00007FF657DB9881  mov         qword ptr [vkEnumerateInstanceLayerProperties (07FF6586AD878h)],rax  
#endif /* defined(VK_VERSION_1_0) */
#if defined(VK_VERSION_1_1)
	vkEnumerateInstanceVersion = (PFN_vkEnumerateInstanceVersion)load(context, "vkEnumerateInstanceVersion");
00007FF657DB9888  lea         rdx,[known_ext_strs+320h (07FF658652080h)]  

Capture2

RAX = 00007FFB71105240 RBX = 0000000000000000 RCX = 00007FF658652030 RDX = 0000000518B85BDE RSI = 0000000000000000 RDI = 0000009B5DBFF4A0 R8  = 0000000000000098 R9  = FEFEFEFEFEFEFEFF R10 = FEFEFEFEFEFEFEFF R11 = 8080808080808080 R12 = 0000000000000000 R13 = 0000000000000000 R14 = 0000000000000000 R15 = 0000000000000000 RIP = 00007FF657DB9853 RSP = 0000009B5DBFF480 RBP = 0000009B5DBFF510 EFL = 00010200 

0x00007FF656E7FEEA = 00CCE9005995CBE9 
zeux commented

I'm wondering if you removed the dependency on vulkan-1.lib from the linker settings? If it's still there it might cause something like that due to a conflict between volk (which dynamically loads functions) and vulkan-1 (which statically binds them to DLL imports).

Bingo! This is it!
Fixed.

zeux commented

Great - I'll add this to the README since it's easy to miss.