After I decided to enable the VK_KHR_SWAPCHAIN_EXTENSION_NAME extension, I started getting the error “access rights violation when reading at address 0xFFFFFFFFFFFFFFFF.” in the vkCreateInstance execution line.
After debugging, I noticed that the problem was filling the ppEnabledExtensionNames value of the VkInstanceCreateInfo structure. I decided to wrap the glfw extensions into a vector and use that to populate the structure. Here is the code for the function to fill this structure.
VkInstanceCreateInfo VulkanManager::paste_create_info(VkApplicationInfo* app_info)
{
VkInstanceCreateInfo create_info{};
vector<const char*> device_extensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};
uint32_t glfw_extensions_count = 0;
const char** glfw_extensions;
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
create_info.pApplicationInfo = app_info;
glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_extensions_count);
for (int i = 0; i < glfw_extensions_count; i++)
device_extensions.push_back(glfw_extensions[i]);
create_info.enabledExtensionCount = (uint32_t) device_extensions.size();
create_info.ppEnabledExtensionNames = device_extensions.data();
create_info.enabledLayerCount = 0;
return create_info;
}
Code of filling VkApplicationInfo structure:
{
VkApplicationInfo app_info{};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.pApplicationName = "Triangle";
app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
app_info.pEngineName = "No Engine";
app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0);
app_info.apiVersion = VK_API_VERSION_1_0;
return app_info;
}
And code of creating vulkan instance:
void VulkanManager::create_vulkan()
{
VkApplicationInfo app_info = VulkanManager::paste_app_info();
VkInstanceCreateInfo create_info = VulkanManager::paste_create_info(&app_info);
Most likely this is an error related to pointers; pointers can lose their value while being transferred to a vector
The
device_extensionsinVulkanManager::paste_create_info()will be out of scope after you returnedcreate_info, thus when you callvkCreateInstance(create_info)somewhere down the line,create_info.ppEnabledExtensionNameswill be pointing to an invalid address, causing memory access violation.As a side-note, you should rename
device_extensionstoinstance_extensionssince those are two different concepts as mentioned here.