创建逻辑设备时获取访问冲突 [英] Getting access violation while creating logical devices

查看:38
本文介绍了创建逻辑设备时获取访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

VkLayer_khronos_validation.dll 抛出异常在 0x00007FFA5252DD05 (VkLayer_khronos_validation.dll) 访问冲突读取位置 0xFFFFFFFFFFFFFFFF 处抛出异常.

Exception thrown at VkLayer_khronos_validation.dll Exception thrown at 0x00007FFA5252DD05 (VkLayer_khronos_validation.dll) Access violation reading location 0xFFFFFFFFFFFFFFFF.

我的代码:

void LogicalDevice::createLogicalDevice(VkPhysicalDevice pDevice){
VkDeviceQueueCreateInfo qcreateInfo;
qcreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
QueueFamiliesIndices indices = PhysicalDevice::findQueueFamilies(pDevice);
qcreateInfo.queueFamilyIndex = indices.graphicsFamily.value();
qcreateInfo.queueCount = 1;
float queuePriority = 1.0f;
qcreateInfo.pQueuePriorities = &queuePriority;

VkPhysicalDeviceFeatures deviceFeatures = {};

VkDeviceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createInfo.pQueueCreateInfos = &qcreateInfo;
createInfo.queueCreateInfoCount = 1;
createInfo.pEnabledFeatures = &deviceFeatures;

createInfo.enabledExtensionCount = 0;

if (ValidationLayers::enableValidationLayers){
     createInfo.enabledLayerCount = static_cast<uint32_t>(ValidationLayers::validationLayers.size());
     createInfo.ppEnabledLayerNames = ValidationLayers::validationLayers.data();

}
else{
     createInfo.enabledLayerCount = 0;
     createInfo.pNext = nullptr;
}
createInfo.flags = 0;

if (vkCreateDevice(pDevice, &createInfo ,nullptr, &device) != VK_SUCCESS){
    std::cout << "Failed to create Logical Device";
}

}

推荐答案

未初始化 VkDeviceQueueCreateInfo.未初始化的指针 (pNext) 会导致错误的指针取消引用.它发生在调试模式下,因为它使用调试内存模式.在 Release 模式下,一个未初始化的值通常是 0.

Uninitialized VkDeviceQueueCreateInfo. Unitialized pointer (pNext) leads to bad pointer dereference. It happens in the Debug mode, because it uses debug memory pattern. In Release mode an uninitialized value often happens to be 0.

在 Vulkan 的 C 绑定中处理此问题的典型方法之一是使用 {}struct 进行零初始化.例如.VkDeviceQueueCreateInfo dqci = {};.或者在 C99 和 C++20 中有指定的初始值设定项.对于大多数 Vulkan 参数,零是一个不错的默认值.

One of the typical ways to deal with this in C bindings of Vulkan is to zero-initialize structs with {}. E.g. VkDeviceQueueCreateInfo dqci = {};. Or there are designated initializers in C99 and C++20. Zero is a decent default value for majority of Vulkan parameters.

这篇关于创建逻辑设备时获取访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆