Vulkan初始化代码中出现奇怪的C6385警告

时间:2019-06-09 20:51:41

标签: c++ visual-studio warnings vulkan

我正在制作Vulkan初始化程序,并试图打印出Vulkan可以识别的物理设备的属性。我没有遇到任何错误或崩溃,但是却遇到了一个可怕的问题:“ C6385从'physicalDevices'读取无效数据:可读大小为'physicalDeviceCount * 4'字节,但可能会读取'8'字节。”警告。由于它正在产生任何实际的问题,并且我已经读到有时对此会产生误报,所以它不会打扰我太多,但我认为我正在与此相关的问题中进行一些可能的问题。

在printStats()中运行的代码似乎不是问题。 我试图控制可能发生缓冲区溢出的情况(例如,使用if(physicalDeviceCount)),但是它似乎并没有消除警告。

// VulkanTest.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include "vulkan\vulkan.h"

#define ASSERT_VULKAN(val)\
        if(val != VK_SUCCESS){\
            __debugbreak();\
        }


VkInstance instance;

void printStats(VkPhysicalDevice& device) {
    VkPhysicalDeviceProperties properties;
    vkGetPhysicalDeviceProperties(device, &properties);

    VkPhysicalDeviceFeatures features;
    vkGetPhysicalDeviceFeatures(device, &features);

    VkPhysicalDeviceMemoryProperties memProp;
    vkGetPhysicalDeviceMemoryProperties(device, &memProp);

    std::cout << properties.deviceName << std::endl;
    uint32_t apiVersion = properties.apiVersion;
    std::cout << VK_VERSION_MAJOR(apiVersion) << "." << VK_VERSION_MINOR(apiVersion) << "." << VK_VERSION_PATCH(apiVersion) << std::endl;
    std::cout << properties.driverVersion << std::endl;
    std::cout << properties.vendorID << std::endl;
    std::cout << properties.deviceID << std::endl;
    std::cout << properties.deviceType << std::endl;

    std::cout << features.geometryShader << std::endl;



}

int main()
{
    VkApplicationInfo appInfo;
    appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appInfo.pNext = NULL;
    appInfo.pApplicationName = "VulkanTest";
    appInfo.applicationVersion = VK_MAKE_VERSION(0, 0, 0);
    appInfo.pEngineName = "Vulkan";
    appInfo.engineVersion = VK_MAKE_VERSION(0, 0, 0);
    appInfo.apiVersion = VK_API_VERSION_1_1;

    VkInstanceCreateInfo instanceInfo;
    instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    instanceInfo.pNext = NULL;
    instanceInfo.flags = 0;
    instanceInfo.pApplicationInfo = &appInfo;
    instanceInfo.enabledLayerCount = 0;
    instanceInfo.ppEnabledLayerNames = NULL;
    instanceInfo.enabledExtensionCount = 0;
    instanceInfo.ppEnabledExtensionNames = NULL;


    VkResult result = vkCreateInstance(&instanceInfo, NULL, &instance);
    ASSERT_VULKAN(result);

    uint32_t physicalDeviceCount = 0;
    result = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, NULL);
    ASSERT_VULKAN(result);

    VkPhysicalDevice* physicalDevices = new VkPhysicalDevice[physicalDeviceCount];

    result = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices);
    ASSERT_VULKAN(result);

        //warning here
    for (int i = 0; i < int(physicalDeviceCount); i++) {
        printStats(physicalDevices[i]);
    }

    return 0;
}

警告C6385从'physicalDevices'读取无效数据:可读大小为'physicalDeviceCount * 4'字节,但可以读取'8'字节。 行:74

0 个答案:

没有答案