vkCreateWin32SurfaceKHR access violation

Hello everyone,
I get an access violation exception when execute vkCreateWin32SurfaceKHR: Exception thrown at 0x0000000000000000 in MIO_Vulkan_Cookbook.exe: 0xC0000005: Access violation executing location 0x0000000000000000.

that is strange because every parameters seems ok:

vkCreateWin32SurfaceKHR(instance, &surface_create_info, NULL, &presentation_surface)

Instance: 0x000001082d3d0a30 {…}

surface_create_info: {sType=VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR (1000009000) pNext=0x0000000000000000 flags=0 …
hinstance=MIO_Vulkan_Cookbook.exe!0x00007ff760d60000 {unused=9460301 }
hwnd=0x00000000002c0be8 {unused=??? }
}

presentation_surface: 0x0000000000000000 <NULL>

Could someone help me?
Thank you

Looks like you are calling nullptr.

What is the type and value of vkCreateWin32SurfaceKHR. Which loader are you using?

Hello krOoze, sorry but I don’t understand, the arguments and its value used to call vkCreateWin32SurfaceKHR are those I describedin my qyestion:

Instance: 0x000001082d3d0a30 {…}

surface_create_info: {sType=VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO _KHR (1000009000) pNext=0x0000000000000000 flags=0 …
hinstance=MIO_Vulkan_Cookbook.exe!0x00007ff760d600 00 {unused=9460301 }
hwnd=0x00000000002c0be8 {unused=??? }
}

presentation_surface: 0x0000000000000000 <NULL>

This is a copy using breakpoint on function call

Thank you

What I mean is that you are probably calling function pointer that has a value of nullptr. Which may happen if you are using third-party Vulkan loader…

I’m using vulkan-1.dll.
I had disable the function prototypes defined in the vulkan.h header file and loaded function pointers dynamically. So you think that I have problems loading fuction pointer? How can I check?

Anyway I checked and you are right, function pointer is NULL, but I don’t understand why, all other functions pointer are ok

Dunno, show me yer code.
Maybe typo in the command name, for which the vkGetInstanceProcAddr would return nullptr.
Or you do not have VK_KHR_win32_surface extension enabled.

Solved! It Was a vkGetInstanceProcAddr problem, I thought that I called this function but it seems that I forgot.
Anyway thank you very much krOoze, you helped me a lot!
The problem is that I use #define macro and somewhere I forgot to call it.

Anyway I don’t understand a thing, I’m following Vulkan cookbook examples, and I have (for example) in header file: #define EXPORTED_VULKAN_FUNCTION( name ) extern PFN_##name name;
and then in cpp file #define EXPORTED_VULKAN_FUNCTION( name ) PFN_##name name;

Why I can’t define in header file like in cpp? If I put directly in head#define EXPORTED_VULKAN_FUNCTION( name ) PFN_##name name; I got LNK2005 error, like “functions already defined in file.obj

I would assume because of the One Definition Rule. Do you have include guards in the header?

I can’t check atm, but I think that there is the #pragma once, but is it not enough to call header inly once?