GLFW glfwCreateWindowSurface return -7

GLFW glfwCreateWindowSurface return -7

我在互联网上找到了这段代码,但我收到了这个错误:VK_ERROR_EXTENSION_NOT_PRESENT(-7) on glfwCreateWindowSurface

result = glfwCreateWindowSurface(instance, window, nullptr, &surface);
std::cout << result; // -7

代码:

#include <iostream>
#define VK_USE_PLATFORM_WIN32_KHR
#define GLFW_INCLUDE_VULKAN
#include <GLFW\glfw3.h>
//#include <vulkan\vulkan.h>
#include <vector>
#define ASSERT_VULKAN(val)\
        if (val != VK_SUCCESS) {\
           __debugbreak();\
        }
 
VkInstance instance;
VkSurfaceKHR surface;
GLFWwindow *window;
 
void startGlfw() {
 
    glfwInit();
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
 
    window = glfwCreateWindow(400, 300, "A", nullptr, nullptr);
 
}
 
void startVulkan() {
    VkApplicationInfo appInfo;
    appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appInfo.pNext = nullptr;
    appInfo.pApplicationName = "Vulkan";
    appInfo.applicationVersion = VK_MAKE_VERSION(0, 0, 0);
    appInfo.pEngineName = "enginetest";
    appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
    appInfo.apiVersion = VK_API_VERSION_1_0;
 
    uint32_t amountOfLayers = 0;
    vkEnumerateInstanceLayerProperties(&amountOfLayers, nullptr);
    VkLayerProperties *layers = new VkLayerProperties[amountOfLayers];
    vkEnumerateInstanceLayerProperties(&amountOfLayers, layers);
 
    std::cout << "Amount of Instance Layers: " << amountOfLayers << std::endl;
 
    uint32_t amountOfExtensions = 0;
    vkEnumerateInstanceExtensionProperties(nullptr, &amountOfExtensions, nullptr);
    VkExtensionProperties *extensions = new VkExtensionProperties[amountOfExtensions];
    vkEnumerateInstanceExtensionProperties(nullptr, &amountOfExtensions, extensions);
 
    const std::vector<const char*> validationLayers = {
        "VK_LAYER_LUNARG_standard_validation"
    };
 
    uint32_t amountOfGlfwExtensions = 0;
    auto glfwExtensions = glfwGetRequiredInstanceExtensions(&amountOfExtensions);
 
    VkInstanceCreateInfo instanceInfo;
    instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    instanceInfo.pNext = nullptr;
    instanceInfo.flags = 0;
    instanceInfo.pApplicationInfo = &appInfo;
    instanceInfo.enabledLayerCount = validationLayers.size();
    instanceInfo.ppEnabledLayerNames = validationLayers.data();
    instanceInfo.enabledExtensionCount = amountOfGlfwExtensions;
    instanceInfo.ppEnabledExtensionNames = glfwExtensions;

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

    result = glfwCreateWindowSurface(instance, window, nullptr, &surface);
    std::cout << result; // -7
    ASSERT_VULKAN(result);
}

int main() {
    startGlfw();
    startVulkan(); 
}

谁能帮帮我?谢谢

    uint32_t amountOfGlfwExtensions = 0;
    auto glfwExtensions = glfwGetRequiredInstanceExtensions(&amountOfExtensions);

注意 amountOfGlfwExtensionsamountOfExtensions 变量名称。 amountOfGlfwExtensions 保持 0,因此与 vkCreateInstance 一起使用时不会启用任何扩展。