From 346d1d5b71626fa61bc64dcde026a349c01335f9 Mon Sep 17 00:00:00 2001 From: tgfrerer Date: Tue, 7 Feb 2023 16:10:01 +0000 Subject: [PATCH] [backend] fix off-by one 0 as swapchain index represents invalid swapchain, as we use the value of indices as opaque handles. The first valid index will therefore be 1. This commit corrects for this. --- modules/le_backend_vk/le_backend_vk.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/le_backend_vk/le_backend_vk.cpp b/modules/le_backend_vk/le_backend_vk.cpp index 77281622e..679caed8f 100644 --- a/modules/le_backend_vk/le_backend_vk.cpp +++ b/modules/le_backend_vk/le_backend_vk.cpp @@ -979,7 +979,7 @@ static le_swapchain_handle backend_add_swapchain( le_backend_o* self, le_swapcha assert( swapchain ); - uint64_t swapchain_index = ++self->swapchains_next_handle; // note pre-increment + uint64_t swapchain_index = ++self->swapchains_next_handle; // note pre-increment: this is so that index 0 means invalid swapchain char swapchain_name[ 64 ]; @@ -1442,7 +1442,8 @@ static void backend_setup( le_backend_o* self ) { if ( !self->swapchains.empty() ) { // Take the first swapchain, and use this to specify the default format for a color attachment - self->defaultFormatColorAttachment = le::Format( self->swapchains.at( 0 ).swapchain_surface_format.format ); + // Note that we take swapchain with index 1, as index 0 must not exist (it represents an invalid swapchain index or handle) + self->defaultFormatColorAttachment = le::Format( self->swapchains.at( 1 ).swapchain_surface_format.format ); } else { self->defaultFormatColorAttachment = le::Format::eB8G8R8A8Unorm; }