From 260ce526c2fa56f5b297feb44f037d38847b5874 Mon Sep 17 00:00:00 2001 From: orbea Date: Fri, 24 Aug 2018 18:07:57 -0700 Subject: [PATCH] Fix segfaults when starting vulkan without a working vulkan driver. RetroArch will crash in several places when running vulkan in an environment that does not have working vulkan drivers. This should guard against those crashes and allow RetroArch to fail safely in those cases. --- gfx/common/vulkan_common.c | 5 ++++- gfx/drivers/vulkan.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index a736a8c134..7c92a96643 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -1827,7 +1827,10 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk, VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; info.pfnCallback = vulkan_debug_cb; - vkCreateDebugReportCallbackEXT(vk->context.instance, &info, NULL, &vk->context.debug_callback); + + if (vk->context.instance) + vkCreateDebugReportCallbackEXT(vk->context.instance, &info, NULL, + &vk->context.debug_callback); } RARCH_LOG("[Vulkan]: Enabling Vulkan debug layers.\n"); #endif diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index f9fb7095c0..3d162d0118 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -744,6 +744,9 @@ static bool vulkan_init_default_filter_chain(vk_t *vk) memset(&info, 0, sizeof(info)); + if (!vk->context) + return false; + info.device = vk->context->device; info.gpu = vk->context->gpu; info.memory_properties = &vk->context->memory_properties; @@ -832,7 +835,7 @@ static bool vulkan_init_filter_chain(vk_t *vk) static void vulkan_init_resources(vk_t *vk) { - if (!vk) + if (!vk->context) return; vk->num_swapchain_images = vk->context->num_swapchain_images; @@ -855,6 +858,9 @@ static void vulkan_init_static_resources(vk_t *vk) VkPipelineCacheCreateInfo cache = { VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO }; + if (!vk->context) + return; + vkCreatePipelineCache(vk->context->device, &cache, NULL, &vk->pipelines.cache); @@ -2357,6 +2363,9 @@ static void vulkan_viewport_info(void *data, struct video_viewport *vp) video_driver_get_size(&width, &height); + if (!vk) + return; + /* Make sure we get the correct viewport. */ vulkan_set_viewport(vk, width, height, false, true);