微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

这是 g++ for 循环实现或我的代码中的错误

如何解决这是 g++ for 循环实现或我的代码中的错误

我目前正在从事一个 Vulkan 项目。我的交换链中有 2 个图像,但我的应用程序对其进行了 2 次以上的迭代。我看不出有什么问题,而且 CLion、g++ 和 clang++ 不会发出任何警告。


    std::cout << vulkanRendererInternalInfo.swapchainImageCount << std::endl;

    for (uint32_t swapchainImageIndex = 0;
         swapchainImageIndex < vulkanRendererInternalInfo.swapchainImageCount; swapchainImageIndex++) {
        std::cout << "is " << swapchainImageIndex << " < " << vulkanRendererInternalInfo.swapchainImageCount << " "
                  << getTruthValue(swapchainImageIndex < vulkanRendererInternalInfo.swapchainImageCount) << std::endl;

        VkImageViewCreateInfo imageViewCreateInfo = {};
        imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
        imageViewCreateInfo.pNext = nullptr;
        imageViewCreateInfo.flags = 0;
        imageViewCreateInfo.image = vulkanRendererInternalInfo.swapchainImages[swapchainImageIndex];
        imageViewCreateInfo.format = vulkanRendererInternalInfo.swapchainformat;
        imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
        imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_R;
        imageViewCreateInfo.components.g = VK_COMPONENT_SWIZZLE_G;
        imageViewCreateInfo.components.b = VK_COMPONENT_SWIZZLE_B;
        imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_A;
        imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
        imageViewCreateInfo.subresourceRange.baseMipLevel = 0;
        imageViewCreateInfo.subresourceRange.levelCount = 1;
        imageViewCreateInfo.subresourceRange.baseArrayLayer = 0;
        imageViewCreateInfo.subresourceRange.layerCount = 1;
        std::cout << "a " << swapchainImageIndex << std::endl;
        VULKAN_ASSERT(vkCreateImageView(vulkanRendererInternalInfo.device,&imageViewCreateInfo,nullptr,&vulkanRendererInternalInfo.swapchainImageViews[swapchainImageIndex]))
    }

getTruthValue 返回“True”或“False”,VULKAN_ASSERT 是检查 VkResult 的宏。前两次 VkResult 是 VK_SUCCESS,第三次 vkCreateImageView 创建分段错误

当我用 g++ -O3 -march=skylake -ffast-math ...g++ -O3 ...g++ -O1 ... 编译时

2
is 0 < 2 True
a 0
is 1 < 2 True
a 1
is 2 < 2 False
a 2
UNASSIGNED-GeneralParameterError-requiredParameter(ERROR / SPEC): msgNum: -1711571459 - Validation Error: [ UNASSIGNED-GeneralParameterError-requiredParameter ] Object 0: handle = 0x562a0969f6a8,type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x99fb7dfd | vkCreateImageView: required parameter pCreateInfo->image specified as VK_NULL_HANDLE
    Objects: 1
        [0] 0x562a0969f6a8,type: 3,name: NULL
VUID-VkImageViewCreateInfo-image-parameter(ERROR / SPEC): msgNum: 315335852 - Validation Error: [ VUID-VkImageViewCreateInfo-image-parameter ] Object 0: handle = 0x562a089cb8a0,type = VK_OBJECT_TYPE_INSTANCE; | MessageID = 0x12cba4ac | Invalid VkImage Object 0x0. The Vulkan spec states: image must be a valid VkImage handle (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-VkImageViewCreateInfo-image-parameter)
    Objects: 1
        [0] 0x562a089cb8a0,type: 1,name: NULL
Segmentation fault (core dumped)

但是当我使用 g++ -O0 -march=skylake -ffast-math ...clang++ -O3 -march=skylake -ffast-math ...

解决方法

好吧,我想这是一个错误,因为我可以通过在 if 语句后添加 return 0; 来修复它。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。