简体   繁体   English

创建vulkan实例有困难

[英]difficulty creating a vulkan instance

im starting to rebuild a game engine i began writing for openGL, this time the graphical framework is Vulkan based but i can't create my first Vkinstance because of an access violation. 我开始重建游戏引擎,我开始为openGL编写,这次图形框架基于Vulkan,但是由于访问冲突,我无法创建我的第一个Vkinstance。 im following the tutorial on vulkan-tutorial.com, the instance section. 即时消息遵循vulkan-tutorial.com上的实例部分的教程。 i declare a 我宣布一个

Vkinstance instance;

then later i call 然后我打电话给

vkCreateInstance(&createInfo, nullptr, &instance)

and my program breaks citing an access violation. 我的程序因访问冲突而中断。

i have tried making instance a pointer and setting it 我试图使实例成为指针并进行设置

instance = new Vkinstance();

but this doesn't solve the problem. 但这不能解决问题。 i still have the access violation. 我仍然有访问冲突。 this is upseting because iv seen in tutorials Vkinstance created and not initialised and then sent strait to vkCreateInstance on the next line. 这是令人不安的,因为iv在教程中看到了Vkinstance创建但未初始化,然后在下一行将strait发送到vkCreateInstance。 so why am i getting this error? 那我为什么会收到这个错误?

additionaly: instance is a private variable belonging to the class vkCreateInstance is called from. 另外:instance是一个私有变量,属于从其调用的vkCreateInstance类。

EDIT: 编辑:

here is a more complete code segment that you can test 这是您可以测试的更完整的代码段

#define VK_USE_PLATFORM_WIN32_KHR
#include <vulkan/vulkan.h>

int main(int argc, char* argv[]) {
    VkInstance instance;

    VkApplicationInfo appInfo = {};
    appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appInfo.pApplicationName = "Hello Triangle";
    appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
    appInfo.pEngineName = "No Engine";
    appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
    appInfo.apiVersion = VK_API_VERSION_1_0;

    VkInstanceCreateInfo createInfo = {};
    createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    createInfo.pApplicationInfo = &appInfo;
    unsigned int extensionCount = 0;
    const char* extensionNames[] = {
        VK_KHR_SURFACE_EXTENSION_NAME,
        VK_KHR_WIN32_SURFACE_EXTENSION_NAME
    };
    vkEnumerateInstanceExtensionProperties(NULL, &extensionCount, NULL);
    createInfo.enabledExtensionCount = extensionCount;
    createInfo.ppEnabledExtensionNames = extensionNames;
    createInfo.enabledLayerCount = 0;

    if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
        throw std::runtime_error("failed to create instance!");
    }

it breaks vkCreateInstance(&createInfo, nullptr, &instance) at &instance : Access violation reading location 0xCCCCCCCC 它在&instance处打破了vkCreateInstance(&createInfo,nullptr,&instance):访问冲突读取位置0xCCCCCCCC

Your list of instance extension names is fixed to two entries: 您的实例扩展名名称列表固定为两个条目:

const char* extensionNames[] = {
    VK_KHR_SURFACE_EXTENSION_NAME,
    VK_KHR_WIN32_SURFACE_EXTENSION_NAME
};

But you read and pass the total number of all available extensions to the create info: 但是您阅读了所有可用扩展的总数并将其传递给创建信息:

vkEnumerateInstanceExtensionProperties(NULL, &extensionCount, NULL);

createInfo.enabledExtensionCount = extensionCount;
createInfo.ppEnabledExtensionNames = extensionNames;

It's very likely that extensionCount is greater than two and that's why instance creation fails (as it expects more than the two extension names). extensionCount很有可能大于两个,这就是为什么实例创建失败的原因(因为它期望比两个扩展名更多)。

So either also query and pass all available extension names (if you really want to enable all) as you did with the extension count or set createInfo.enabledExtensionCount to the size of the array of your predefined extension list. 因此,也可以像处理扩展名一样查询并传递所有可用的扩展名(如果您确实要启用所有扩展名),或者将createInfo.enabledExtensionCount设置为预定义扩展名列表的数组大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM