From 1b22456d0785fcee6e6c2242e3f6e04b36aa512b Mon Sep 17 00:00:00 2001 From: jeromenxp Date: Mon, 18 Jan 2021 17:41:41 +0100 Subject: [PATCH] Change scope of validationExt and validationLayerName variables Pointer to a variable declared into a block statement is stored and used outside of the block by vkCreateInstance. This can lead to segmentation fault. Move the declaration of validationExt/validationLayerName outside of the block to fix the crash. --- base/vulkanexamplebase.cpp | 7 ++++--- examples/computeheadless/computeheadless.cpp | 2 +- examples/renderheadless/renderheadless.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 68029abf..12ccf1f0 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -95,11 +95,12 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size(); instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data(); } + + // The VK_LAYER_KHRONOS_validation contains all current validation functionality. + // Note that on Android this layer requires at least NDK r20 + const char* validationLayerName = "VK_LAYER_KHRONOS_validation"; if (settings.validation) { - // The VK_LAYER_KHRONOS_validation contains all current validation functionality. - // Note that on Android this layer requires at least NDK r20 - const char* validationLayerName = "VK_LAYER_KHRONOS_validation"; // Check if this layer is available at instance level uint32_t instanceLayerCount; vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr); diff --git a/examples/computeheadless/computeheadless.cpp b/examples/computeheadless/computeheadless.cpp index 49566394..5095222d 100644 --- a/examples/computeheadless/computeheadless.cpp +++ b/examples/computeheadless/computeheadless.cpp @@ -170,9 +170,9 @@ public: } } + const char *validationExt = VK_EXT_DEBUG_REPORT_EXTENSION_NAME; if (layersAvailable) { instanceCreateInfo.ppEnabledLayerNames = validationLayers; - const char *validationExt = VK_EXT_DEBUG_REPORT_EXTENSION_NAME; instanceCreateInfo.enabledLayerCount = layerCount; instanceCreateInfo.enabledExtensionCount = 1; instanceCreateInfo.ppEnabledExtensionNames = &validationExt; diff --git a/examples/renderheadless/renderheadless.cpp b/examples/renderheadless/renderheadless.cpp index a0126cf3..ba41bf8a 100644 --- a/examples/renderheadless/renderheadless.cpp +++ b/examples/renderheadless/renderheadless.cpp @@ -200,9 +200,9 @@ public: } } + const char *validationExt = VK_EXT_DEBUG_REPORT_EXTENSION_NAME; if (layersAvailable) { instanceCreateInfo.ppEnabledLayerNames = validationLayers; - const char *validationExt = VK_EXT_DEBUG_REPORT_EXTENSION_NAME; instanceCreateInfo.enabledLayerCount = layerCount; instanceCreateInfo.enabledExtensionCount = 1; instanceCreateInfo.ppEnabledExtensionNames = &validationExt;