我剛開始學習Vulkan。我有Graham Sellers編寫的「Vulkan編程指南」一書,以及我係統中帶有AMDGPU專業版驅動程序的RX 480。我正在運行Arch Linux,並且能夠在我的系統上運行一些Vulkan演示。vkCreateInstance導致分段錯誤
我有一個導致分段錯誤的最小代碼塊。奇怪的是,在我爲了提出這個問題而生成這個塊的方法中,我確實使用了從構造函數調用vkCreateInstance()的方式運行,並且在向代碼中添加try/catch時首先發現了分段錯誤。現在
,即使沒有的try/catch這將導致分段錯誤:
#include <iostream>
#include <vulkan/vulkan.h>
int main(int argv, char* argc[])
{
VkInstance* instance;
VkApplicationInfo appInfo = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = NULL,
.pApplicationName = "Step 1",
.applicationVersion = 1,
.pEngineName = NULL,
.engineVersion = 0,
.apiVersion = VK_MAKE_VERSION(1, 0, 26) }; //This is what vulkanCapsViewer says my API version is.
VkInstanceCreateInfo createInfo = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = NULL,
.flags = 0 };
createInfo.pApplicationInfo = &appInfo;
createInfo.enabledExtensionCount = 0;
createInfo.ppEnabledExtensionNames = NULL;
createInfo.enabledLayerCount = 0;
createInfo.ppEnabledLayerNames = NULL;
std::cout << "1\n";
VkResult result = vkCreateInstance(&createInfo, NULL, instance);
std::cout << "2\n";
if(result != VK_SUCCESS) std::cout << "Failed to create a Vulkan instance: " << result << std::endl;
std::cout << "3\n";
return 0;
}
輸出是:
93> ./create_seg_fault
1
Segmentation fault (core dumped)
指定的初始化程序不是C++特徵。所以你的代碼使用C和C++的混合。 –