GPU: Fix crash on Android upon returning from the background

This commit is contained in:
Arnoldo Adonaí Barón Robles
2025-12-10 10:27:13 -06:00
committed by Ethan Lee
parent c2710bd4e8
commit e5731f9bac

View File

@@ -4363,7 +4363,9 @@ static bool VULKAN_INTERNAL_QuerySwapchainSupport(
&supportsPresent);
// Initialize these in case anything fails
outputDetails->formats = NULL;
outputDetails->formatsLength = 0;
outputDetails->presentModes = NULL;
outputDetails->presentModesLength = 0;
if (!supportsPresent) {
@@ -4386,22 +4388,33 @@ static bool VULKAN_INTERNAL_QuerySwapchainSupport(
surface,
&outputDetails->formatsLength,
NULL);
CHECK_VULKAN_ERROR_AND_RETURN(result, vkGetPhysicalDeviceSurfaceFormatsKHR, false);
if (result != VK_SUCCESS) {
// Make sure the driver didn't mess up this value.
outputDetails->formatsLength = 0;
CHECK_VULKAN_ERROR_AND_RETURN(result, vkGetPhysicalDeviceSurfaceFormatsKHR, false);
}
result = renderer->vkGetPhysicalDeviceSurfacePresentModesKHR(
physicalDevice,
surface,
&outputDetails->presentModesLength,
NULL);
CHECK_VULKAN_ERROR_AND_RETURN(result, vkGetPhysicalDeviceSurfacePresentModesKHR, false);
if (result != VK_SUCCESS) {
// Make sure the driver didn't mess up this value.
outputDetails->presentModesLength = 0;
// Reset this one, too.
outputDetails->formatsLength = 0;
CHECK_VULKAN_ERROR_AND_RETURN(result, vkGetPhysicalDeviceSurfacePresentModesKHR, false);
}
// Generate the arrays, if applicable
outputDetails->formats = NULL;
if (outputDetails->formatsLength != 0) {
outputDetails->formats = (VkSurfaceFormatKHR *)SDL_malloc(
sizeof(VkSurfaceFormatKHR) * outputDetails->formatsLength);
if (!outputDetails->formats) { // OOM
outputDetails->formatsLength = 0;
outputDetails->presentModesLength = 0;
return false;
}
@@ -4412,17 +4425,22 @@ static bool VULKAN_INTERNAL_QuerySwapchainSupport(
outputDetails->formats);
if (result != VK_SUCCESS) {
SDL_free(outputDetails->formats);
outputDetails->formats = NULL;
outputDetails->formatsLength = 0;
outputDetails->presentModesLength = 0;
CHECK_VULKAN_ERROR_AND_RETURN(result, vkGetPhysicalDeviceSurfaceFormatsKHR, false);
}
}
outputDetails->presentModes = NULL;
if (outputDetails->presentModesLength != 0) {
outputDetails->presentModes = (VkPresentModeKHR *)SDL_malloc(
sizeof(VkPresentModeKHR) * outputDetails->presentModesLength);
if (!outputDetails->presentModes) { // OOM
SDL_free(outputDetails->formats);
outputDetails->formats = NULL;
outputDetails->formatsLength = 0;
outputDetails->presentModesLength = 0;
return false;
}
@@ -4434,6 +4452,10 @@ static bool VULKAN_INTERNAL_QuerySwapchainSupport(
if (result != VK_SUCCESS) {
SDL_free(outputDetails->formats);
SDL_free(outputDetails->presentModes);
outputDetails->formats = NULL;
outputDetails->presentModes = NULL;
outputDetails->formatsLength = 0;
outputDetails->presentModesLength = 0;
CHECK_VULKAN_ERROR_AND_RETURN(result, vkGetPhysicalDeviceSurfacePresentModesKHR, false);
}
}
@@ -4526,12 +4548,6 @@ static Uint32 VULKAN_INTERNAL_CreateSwapchain(
windowData->surface,
NULL);
windowData->surface = VK_NULL_HANDLE;
if (swapchainSupportDetails.formatsLength > 0) {
SDL_free(swapchainSupportDetails.formats);
}
if (swapchainSupportDetails.presentModesLength > 0) {
SDL_free(swapchainSupportDetails.presentModes);
}
return false;
}