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