mirror of
https://github.com/love2d/love.git
synced 2026-08-21 21:15:09 +02:00
vulkan: fix crash when recreating swapchain
This commit is contained in:
@@ -41,12 +41,8 @@ const std::vector<const char*> deviceExtensions = {
|
|||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
constexpr bool enableValidationLayers = false;
|
constexpr bool enableValidationLayers = false;
|
||||||
#else
|
#else
|
||||||
#ifdef LOVE_ANDROID
|
|
||||||
constexpr bool enableValidationLayers = false;
|
|
||||||
#else
|
|
||||||
constexpr bool enableValidationLayers = true;
|
constexpr bool enableValidationLayers = true;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr int MAX_FRAMES_IN_FLIGHT = 2;
|
constexpr int MAX_FRAMES_IN_FLIGHT = 2;
|
||||||
|
|
||||||
@@ -1012,7 +1008,7 @@ void Graphics::createSwapChain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createInfo.preTransform = swapChainSupport.capabilities.currentTransform;
|
createInfo.preTransform = swapChainSupport.capabilities.currentTransform;
|
||||||
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
createInfo.compositeAlpha = chooseCompositeAlpha(swapChainSupport.capabilities);
|
||||||
createInfo.presentMode = presentMode;
|
createInfo.presentMode = presentMode;
|
||||||
createInfo.clipped = VK_TRUE;
|
createInfo.clipped = VK_TRUE;
|
||||||
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
||||||
@@ -1091,6 +1087,20 @@ VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabiliti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkCompositeAlphaFlagBitsKHR Graphics::chooseCompositeAlpha(const VkSurfaceCapabilitiesKHR &capabilities) {
|
||||||
|
if (capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) {
|
||||||
|
return VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||||
|
} else if (capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) {
|
||||||
|
return VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
|
||||||
|
} else if (capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) {
|
||||||
|
return VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
|
||||||
|
} else if (capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR) {
|
||||||
|
return VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR;
|
||||||
|
} else {
|
||||||
|
throw love::Exception("failed to find composite alpha");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::createImageViews() {
|
void Graphics::createImageViews() {
|
||||||
swapChainImageViews.resize(swapChainImages.size());
|
swapChainImageViews.resize(swapChainImages.size());
|
||||||
|
|
||||||
@@ -1673,9 +1683,11 @@ void Graphics::cleanupSwapChain() {
|
|||||||
for (const auto& [key, val] : framebuffers) {
|
for (const auto& [key, val] : framebuffers) {
|
||||||
vkDestroyFramebuffer(device, val, nullptr);
|
vkDestroyFramebuffer(device, val, nullptr);
|
||||||
}
|
}
|
||||||
|
framebuffers.clear();
|
||||||
for (auto & swapChainImageView : swapChainImageViews) {
|
for (auto & swapChainImageView : swapChainImageViews) {
|
||||||
vkDestroyImageView(device, swapChainImageView, nullptr);
|
vkDestroyImageView(device, swapChainImageView, nullptr);
|
||||||
}
|
}
|
||||||
|
swapChainImageViews.clear();
|
||||||
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ private:
|
|||||||
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
|
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
|
||||||
VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
|
VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
|
||||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||||
|
VkCompositeAlphaFlagBitsKHR chooseCompositeAlpha(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||||
void createSwapChain();
|
void createSwapChain();
|
||||||
void createImageViews();
|
void createImageViews();
|
||||||
VkFramebuffer createFramebuffer(FramebufferConfiguration);
|
VkFramebuffer createFramebuffer(FramebufferConfiguration);
|
||||||
|
|||||||
Reference in New Issue
Block a user