Skip to content

Commit 2e7caa5

Browse files
authored
Fix portability errors and null device crash on macOS/iOS for hello_triangle_1_3 (#1268)
* Fix portability errors and null device crash on macOS/iOS for hello_triangle_1_3 * Update copyright year
1 parent deb3e20 commit 2e7caa5

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2024, Huawei Technologies Co., Ltd.
1+
/* Copyright (c) 2024-2025, Huawei Technologies Co., Ltd.
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -165,6 +165,18 @@ void HelloTriangleV13::init_instance()
165165
}
166166
#endif
167167

168+
#if (defined(VKB_ENABLE_PORTABILITY))
169+
required_instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
170+
bool portability_enumeration_available = false;
171+
if (std::any_of(available_instance_extensions.begin(),
172+
available_instance_extensions.end(),
173+
[](VkExtensionProperties const &extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
174+
{
175+
required_instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
176+
portability_enumeration_available = true;
177+
}
178+
#endif
179+
168180
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
169181
required_instance_extensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
170182
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
@@ -241,6 +253,13 @@ void HelloTriangleV13::init_instance()
241253
}
242254
#endif
243255

256+
#if (defined(VKB_ENABLE_PORTABILITY))
257+
if (portability_enumeration_available)
258+
{
259+
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
260+
}
261+
#endif
262+
244263
// Create the Vulkan instance
245264
VK_CHECK(vkCreateInstance(&instance_info, nullptr, &context.instance));
246265

@@ -1146,7 +1165,10 @@ void HelloTriangleV13::transition_image_layout(
11461165
HelloTriangleV13::~HelloTriangleV13()
11471166
{
11481167
// Don't release anything until the GPU is completely idle.
1149-
vkDeviceWaitIdle(context.device);
1168+
if (context.device != VK_NULL_HANDLE)
1169+
{
1170+
vkDeviceWaitIdle(context.device);
1171+
}
11501172

11511173
for (auto &per_frame : context.per_frame)
11521174
{

0 commit comments

Comments
 (0)