Skip to content

Commit 7e5cd04

Browse files
committed
Fix Instance creation in 01_instance_creation.cpp
1 parent b6b2bac commit 7e5cd04

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

attachments/01_instance_creation.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <algorithm>
12
#include <iostream>
23
#include <stdexcept>
34
#include <cstdlib>
@@ -58,11 +59,27 @@ class HelloTriangleApplication {
5859
.pEngineName = "No Engine",
5960
.engineVersion = VK_MAKE_VERSION( 1, 0, 0 ),
6061
.apiVersion = vk::ApiVersion14 };
62+
63+
// Get the required instance extensions from GLFW.
6164
uint32_t glfwExtensionCount = 0;
6265
auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
66+
67+
// Check if the required GLFW extensions are supported by the Vulkan implementation.
68+
auto extensionProperties = context.enumerateInstanceExtensionProperties();
69+
for (uint32_t i = 0; i < glfwExtensionCount; ++i)
70+
{
71+
if (std::ranges::none_of(extensionProperties,
72+
[glfwExtension = glfwExtensions[i]](auto const& extensionProperty)
73+
{ return strcmp(extensionProperty.extensionName, glfwExtension) == 0; }))
74+
{
75+
throw std::runtime_error("Required GLFW extension not supported: " + std::string(glfwExtensions[i]));
76+
}
77+
}
78+
6379
vk::InstanceCreateInfo createInfo{
6480
.pApplicationInfo = &appInfo,
65-
.ppEnabledLayerNames = glfwExtensions};
81+
.enabledExtensionCount = glfwExtensionCount,
82+
.ppEnabledExtensionNames = glfwExtensions};
6683
instance = vk::raii::Instance(context, createInfo);
6784
}
6885
};

0 commit comments

Comments
 (0)