Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello_triangle sample should avoid referencing a retired swapchain #1015 #1019

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions samples/api/hello_triangle/hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ void HelloTriangle::init_instance(Context &context,
{
LOGI("Initializing vulkan instance.");

if (volkInitialize())
{
throw std::runtime_error("Failed to initialize volk.");
}
if (volkInitialize())
{
throw std::runtime_error("Failed to initialize volk.");
}

uint32_t instance_extension_count;
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, nullptr));
Expand Down Expand Up @@ -509,6 +509,11 @@ void HelloTriangle::init_swapchain(Context &context)
info.clipped = true;
info.oldSwapchain = old_swapchain;

uint32_t image_count;
if (old_swapchain != VK_NULL_HANDLE)
{
VK_CHECK(vkGetSwapchainImagesKHR(context.device, old_swapchain, &image_count, nullptr));
}
VK_CHECK(vkCreateSwapchainKHR(context.device, &info, nullptr, &context.swapchain));

if (old_swapchain != VK_NULL_HANDLE)
Expand All @@ -518,9 +523,6 @@ void HelloTriangle::init_swapchain(Context &context)
vkDestroyImageView(context.device, image_view, nullptr);
}

uint32_t image_count;
VK_CHECK(vkGetSwapchainImagesKHR(context.device, old_swapchain, &image_count, nullptr));

for (size_t i = 0; i < image_count; i++)
{
teardown_per_frame(context, context.per_frame[i]);
Expand All @@ -533,7 +535,6 @@ void HelloTriangle::init_swapchain(Context &context)

context.swapchain_dimensions = {swapchain_size.width, swapchain_size.height, format.format};

uint32_t image_count;
VK_CHECK(vkGetSwapchainImagesKHR(context.device, context.swapchain, &image_count, nullptr));

/// The swapchain images.
Expand Down
Loading