Skip to content

Commit fc092c4

Browse files
committed
Fix SwapChain Creation Bug
- The size of the SwapchainImages was not being passed to the collection thus the collection had the correct data but the size was not reflecting leading to an index error when attempting to access the values.
1 parent c0f5ce8 commit fc092c4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

ZEngine/ZEngine/Hardwares/VulkanDevice.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,20 +1065,20 @@ namespace ZEngine::Hardwares
10651065
SwapchainImageHeight = capabilities.currentExtent.height;
10661066
}
10671067

1068-
auto min_image_count = std::clamp(capabilities.minImageCount, capabilities.minImageCount + 1, capabilities.maxImageCount == 0 ? std::numeric_limits<decltype(capabilities.maxImageCount)>::max() : capabilities.maxImageCount);
1068+
auto min_image_count = std::clamp(capabilities.minImageCount, capabilities.minImageCount, capabilities.maxImageCount == 0 ? std::numeric_limits<decltype(capabilities.maxImageCount)>::max() : capabilities.maxImageCount);
10691069
VkSwapchainCreateInfoKHR swapchain_create_info = {
10701070
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .pNext = nullptr, .surface = Surface, .minImageCount = min_image_count, .imageFormat = SurfaceFormat.format, .imageColorSpace = SurfaceFormat.colorSpace, .imageExtent = VkExtent2D{.width = SwapchainImageWidth, .height = SwapchainImageHeight},
10711071
.imageArrayLayers = 1, .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, .preTransform = capabilities.currentTransform, .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, .presentMode = PresentMode, .clipped = VK_TRUE
10721072
};
10731073

10741074
if (SwapchainImageViews.capacity() <= 0)
10751075
{
1076-
SwapchainImageViews.init(Arena, SwapchainImageCount, SwapchainImageCount);
1076+
SwapchainImageViews.init(Arena, SwapchainImageCount);
10771077
}
10781078

10791079
if (SwapchainFramebuffers.capacity() <= 0)
10801080
{
1081-
SwapchainFramebuffers.init(Arena, SwapchainImageCount, SwapchainImageCount);
1081+
SwapchainFramebuffers.init(Arena, SwapchainImageCount);
10821082
}
10831083

10841084
auto scratch = ZGetScratch(Arena);
@@ -1101,7 +1101,9 @@ namespace ZEngine::Hardwares
11011101
ZENGINE_VALIDATE_ASSERT(vkGetSwapchainImagesKHR(LogicalDevice, SwapchainHandle, &SwapchainImageCount, nullptr) == VK_SUCCESS, "Failed to get Images count from Swapchain")
11021102

11031103
Array<VkImage> SwapchainImages = {};
1104+
11041105
SwapchainImages.init(scratch.Arena, SwapchainImageCount, SwapchainImageCount);
1106+
11051107
ZENGINE_VALIDATE_ASSERT(vkGetSwapchainImagesKHR(LogicalDevice, SwapchainHandle, &SwapchainImageCount, SwapchainImages.data()) == VK_SUCCESS, "Failed to get VkImages from Swapchain")
11061108

11071109
/*Transition Image from Undefined to Present_src*/
@@ -1128,12 +1130,12 @@ namespace ZEngine::Hardwares
11281130

11291131
for (int i = 0; i < SwapchainImageCount; ++i)
11301132
{
1131-
SwapchainImageViews[i] = CreateImageView(SwapchainImages[i], SurfaceFormat.format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
1133+
SwapchainImageViews.push(CreateImageView(SwapchainImages[i], SurfaceFormat.format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT));
11321134

11331135
Array<VkImageView> fb_images_views;
11341136
fb_images_views.init(scratch.Arena, 1);
11351137
fb_images_views.push(SwapchainImageViews[i]);
1136-
SwapchainFramebuffers[i] = CreateFramebuffer(ArrayView{fb_images_views}, SwapchainAttachment->GetHandle(), SwapchainImageWidth, SwapchainImageHeight);
1138+
SwapchainFramebuffers.push(CreateFramebuffer(ArrayView{fb_images_views}, SwapchainAttachment->GetHandle(), SwapchainImageWidth, SwapchainImageHeight));
11371139
}
11381140

11391141
ZReleaseScratch(scratch);

ZEngine/ZEngine/Hardwares/VulkanDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ namespace ZEngine::Hardwares
538538
bool HasSeperateTransfertQueueFamily = false;
539539
const char* ApplicationName = "Tetragrama";
540540
const char* EngineName = "ZEngine";
541-
uint32_t SwapchainImageCount = 4;
541+
uint32_t SwapchainImageCount = 3;
542542
uint32_t SwapchainImageIndex = std::numeric_limits<uint8_t>::max();
543543
uint32_t CurrentFrameIndex = std::numeric_limits<uint8_t>::max();
544544
uint32_t PreviousFrameIndex = std::numeric_limits<uint8_t>::max();

0 commit comments

Comments
 (0)