Exception thrown from vkCreateInstance when init GLFW

Hi, I have already successfully run the code from the template of Vulkan SDK (${VulkanSDK}\1.2.135.0\Templates\Visual Studio 2017\VulkanProgram). However, when I integrated the code GLFW, I met the following crash error at vkCreateInstance(&instInfo, NULL, &instance); :

Exception thrown at 0x00007FFD17A0B343 (vulkan-1.dll) in VulkanProgram.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

The complete source code is:

/*
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#include <iostream>
#include <vector>

std::vector<const char*> getRequiredExtensions() {
	uint32_t glfwExtensionCount = 0;
	const char** glfwExtensions;
	glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);

	std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);

	extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);

	return extensions;
}

int main()
{
	// Use validation layers if this is a debug build
	std::vector<const char*> layers;
#if defined(_DEBUG)
	layers.push_back("VK_LAYER_KHRONOS_validation");
#endif

	glfwInit();

	//glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
	//glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

	//GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan", nullptr, nullptr);

	// VkApplicationInfo allows the programmer to specifiy some basic information about the
	// program, which can be useful for layers and tools to provide more debug information.
	VkApplicationInfo appInfo = {};
	appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
	appInfo.pNext = NULL;
	appInfo.pApplicationName = "Vulkan Program Template";
	appInfo.applicationVersion = 1;
	appInfo.pEngineName = "LunarG SDK";
	appInfo.engineVersion = 1;
	appInfo.apiVersion = VK_API_VERSION_1_0;

	// VkInstanceCreateInfo is where the programmer specifies the layers and/or extensions that
	// are needed. For now, none are enabled.
	VkInstanceCreateInfo instInfo = {};
	instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
	instInfo.pNext = NULL;
	instInfo.flags = 0;
	instInfo.pApplicationInfo = &appInfo;
	//instInfo.enabledExtensionCount = 0;
	//instInfo.ppEnabledExtensionNames = NULL;

	auto extensions = getRequiredExtensions();
	instInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
	instInfo.ppEnabledExtensionNames = extensions.data();

	instInfo.enabledLayerCount = static_cast<uint32_t>(layers.size());
	instInfo.ppEnabledLayerNames = layers.data();

	// Create the Vulkan instance.
	VkInstance instance;
	VkResult result = vkCreateInstance(&instInfo, NULL, &instance);
	if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
		std::cout << "Unable to find a compatible Vulkan Driver." << std::endl;
		return 1;
	}
	else if (result) {
		std::cout << "Could not create a Vulkan instance (for unknown reasons)." << std::endl;
		return 1;
	}

	// Normally, a program would do something with the instance here. This, however, is just a
	// simple demo program, so we just finish up right away.

	vkDestroyInstance(instance, NULL);

	return 0;
}

The error can be suppressed if disable GLFW with removing the code glfwInit();

System Configuration:

Win 7 OS; Visual Studio 2017(v141);LuanG vulkan SDK-1.2.135.0; glfw3.3.2

C/C++ configuration in VS:

/GS /W3 /Zc:wchar_t /I${VulkanSDK}\1.2.135.0\Include" /I"${GLFW}\glfw\glfw-3.3.2\include" /ZI /Gm- /Od /Fd"x64\Debug\vc141.pdb" /Zc:inline /fp:precise /D “WIN32” /D “_WINDOWS” /D “_CRT_SECURE_NO_WARNINGS” /D “CMAKE_INTDIR=“Debug”” /D “_UNICODE” /D “UNICODE” /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /Fa"x64\Debug" /nologo /Fo"x64\Debug" /Fp"x64\Debug\VulkanProgram.pch" /diagnostics:classic

Link Configuration in VS

/OUT:"${VulkanSDK}\1.2.135.0\Templates\Visual Studio 2017\VulkanProgram\x64\Debug\VulkanProgram.exe" /MANIFEST /NXCOMPAT /PDB:"${VulkanSDK}\1.2.135.0\Templates\Visual Studio 2017\VulkanProgram\x64\Debug\VulkanProgram.pdb" /DYNAMICBASE “vulkan-1.lib” “glfw3.lib” “kernel32.lib” “user32.lib” “gdi32.lib” “winspool.lib” “comdlg32.lib” “advapi32.lib” “shell32.lib” “ole32.lib” “oleaut32.lib” “uuid.lib” “odbc32.lib” “odbccp32.lib” /DEBUG /MACHINE:X64 /ENTRY:“mainCRTStartup” /INCREMENTAL /PGD:"${VulkanSDK}\1.2.135.0\Templates\Visual Studio 2017\VulkanProgram\x64\Debug\VulkanProgram.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /ManifestFile:“x64\Debug\VulkanProgram.exe.intermediate.manifest” /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"${VulkanSDK}\1.2.135.0\Lib" /LIBPATH:"${GLFW}\glfw\glfw-3.3.2\lib\x64" /TLBID:1

Code looks legit, albeit lacks error checking. Works for me.

Check return codes. Use breakpoints to determine what vkCreateInstance actually sees on your PC.

Thanks for your reply.

The code crashed at VkResult result = vkCreateInstance(&instInfo, NULL, &instance); without return any value to result .
With breakpoints, I checked the value instInfo. It seems normally.
The detail of instInfo is

- instInfo {sType=VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO (1) pNext=0x0000000000000000 flags=0 …} VkInstanceCreateInfo
sType VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO (1) VkStructureType
pNext 0x0000000000000000 const void *
flags 0 unsigned int
+ pApplicationInfo 0x000000c6aaaffaf8 {sType=VK_STRUCTURE_TYPE_APPLICATION_INFO (0) pNext=0x0000000000000000 pApplicationName=…} const VkApplicationInfo *
enabledLayerCount 1 unsigned int
+ ppEnabledLayerNames 0x0000028e6fcfb960 {0x00007ff6a1d79590 “VK_LAYER_KHRONOS_validation”} const char * const *
enabledExtensionCount 3 unsigned int
+ ppEnabledExtensionNames 0x0000028e6fd0d200 {0x00007ff6a1dacf90 “VK_KHR_surface”} const char * const *

And the detail of instInfo.pApplicationInfo is

- pApplicationInfo 0x000000c6aaaffaf8 {sType=VK_STRUCTURE_TYPE_APPLICATION_INFO (0) pNext=0x0000000000000000 pApplicationName=…} const VkApplicationInfo *
sType VK_STRUCTURE_TYPE_APPLICATION_INFO (0) VkStructureType
pNext 0x0000000000000000 const void *
+ pApplicationName 0x00007ff6a1d795c0 “Vulkan Program Template” const char *
applicationVersion 1 unsigned int
+ pEngineName 0x00007ff6a1d795f0 “LunarG SDK” const char *
engineVersion 1 unsigned int
apiVersion 4194304 unsigned int

The completely data of instInfo.ppEnabledExtensionNames is “VK_KHR_SURFACE”, “VK_KHR_win32_surface” and “VK_EXT_debug_utils”.

Besides, I also checked the value instInfo if I remove the line glfwInit()'. The only difference is that instInfo.ppEnabledExtensionNamesonly has an element "VK_EXT_debug_utils" and the correspondinginstInfo.enabledExtensionCount` is 1. At such condition, the code passed successfully, which confused me.

I have no idea on how to solved it.

AIS, you should be checking errors. That means const auto success = glfwinit(); if(!success) panic();.

Do other Vulkan apps work for you? Does vulkaninfo and vkcube work?

Last resort you could always get debuggable Loader.

GLFW itself run well. The return value from glfwinit() is True, and the window created by GLFW can also be shown normally with glfwCreateWindow().

vkcube work well in my PC, while vulkaninfo cannot work with followoing message:

WARNING: [loader] Code 0 : D:\Documents\VulkanSDK\1.2.135.0\Bin\VkLayer_device_simulation.json Unexpected manifest file version (expected 1.0.0 or 1.0.1), may cause errors
WARNING: [loader] Code 0 : D:\Documents\VulkanSDK\1.2.135.0\Bin\VkLayer_khronos_validation.json Unexpected manifest file version (expected 1.0.0 or 1.0.1), may cause errors
WARNING: [loader] Code 0 : C:\Program Files\RenderDoc\renderdoc.json Unexpected manifest file version (expected 1.0.0 or 1.0.1), may cause errors
ERROR at c:\vulkansdkbuild\workspace\khronos-tools\repo\vulkaninfo\vulkaninfo.h:642:vkCreateInstance failed with ERROR_EXTENSION_NOT_PRESENT

I am sorry for that I don’t know what does the debuggable Loader refers to .

It is strange that the code can run well if I remove either

	auto extensions = getRequiredExtensions();
	instInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
	instInfo.ppEnabledExtensionNames = extensions.data();

or

	instInfo.enabledLayerCount = static_cast<uint32_t>(layers.size());
	instInfo.ppEnabledLayerNames = layers.data();

Your driver seems pretty old. We are on manifest version 1.1+ for many years. What driver do you have? Try to update.

After checking, I found that the graphic driver was already the latest version.

The graphic card infomatin:

  1. AMD Radeon R5 M230, driver ver. 21.19.128.6 (support Vulkan Driver Ver.1.3.0, Vulkan API Version 1.0.24)
  2. Intel® HD Graphics 5500, driver ver. 20.19.15.4835 (not support Vulkan)

That looks like a four year old driver. I mean go to the AMD webpage and download new driver package.

1 Like

Thanks very much, the problem has been solved after updating the driver of AMD.

While, I have an another PC which met the same problem. The PC has only a graphic card Intel HD 530 with Win 7 OS. Due to the limited of Win 7, I can only upgrade the driver into 15.45.31.5127. The version with 26.20.100.8141 only support Win 10. In short, is there any way to solve the problem for a win 7 PC with intel HD 530.

Well, downgrade the vulkan version can solve the problem for intel HD 530.

15.45 seems relatively recent (Mar 2020). Though apparently stuck at Vulkan 1.0.31.
Normally you should not do this, but it might help to get a standalone Runtime from https://vulkan.lunarg.com/sdk/home (or make it worse :p)

1 Like

Aha, it is really helpful to install the the standalone Runtime. Thank you!