From 896a205e8e05f0f3a419311b5a4cab129260e933 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Fri, 11 Jul 2025 15:21:05 +0200 Subject: [PATCH] ensure swapchains exist before presenting fixes #57 --- src/hooks.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/hooks.cpp b/src/hooks.cpp index 7eff7a9..a7afc26 100644 --- a/src/hooks.cpp +++ b/src/hooks.cpp @@ -142,7 +142,12 @@ namespace { const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) { - auto& deviceInfo = devices.at(device); + auto it = devices.find(device); + if (it == devices.end()) { + Log::warn("hooks", "Created swapchain without device info present"); + return Layer::ovkCreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); + } + auto& deviceInfo = it->second; // update swapchain create info VkSwapchainCreateInfoKHR createInfo = *pCreateInfo; @@ -207,8 +212,27 @@ namespace { VkResult myvkQueuePresentKHR( VkQueue queue, const VkPresentInfoKHR* pPresentInfo) { - auto& deviceInfo = devices.at(swapchainToDeviceTable.at(*pPresentInfo->pSwapchains)); - auto& swapchain = swapchains.at(*pPresentInfo->pSwapchains); + auto it = swapchainToDeviceTable.find(*pPresentInfo->pSwapchains); + if (it == swapchainToDeviceTable.end()) { + Log::warn("hooks2", "Swapchain {:x} not found in swapchainToDeviceTable", + reinterpret_cast(*pPresentInfo->pSwapchains)); + return Layer::ovkQueuePresentKHR(queue, pPresentInfo); + } + auto it2 = devices.find(it->second); + if (it2 == devices.end()) { + Log::warn("hooks2", "Device {:x} not found in devices", + reinterpret_cast(it->second)); + return Layer::ovkQueuePresentKHR(queue, pPresentInfo); + } + auto it3 = swapchains.find(*pPresentInfo->pSwapchains); + if (it3 == swapchains.end()) { + Log::warn("hooks2", "Swapchain {:x} not found in swapchains", + reinterpret_cast(*pPresentInfo->pSwapchains)); + return Layer::ovkQueuePresentKHR(queue, pPresentInfo); + } + + auto& deviceInfo = it2->second; + auto& swapchain = it3->second; // patch vsync NOLINTBEGIN const VkSwapchainPresentModeInfoEXT* presentModeInfo =