Repository: libsdl-org/SDL
File: test/testvulkan.c (C)

Code before:
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,                                   \
                     "vkGetInstanceProcAddr(VK_NULL_HANDLE, \"" #name "\") failed"); \
        quit(2);                                                                     \
    }
#define VULKAN_INSTANCE_FUNCTION(name)
    VULKAN_FUNCTIONS()
#undef VULKAN_DEVICE_FUNCTION
#undef VULKAN_GLOBAL_FUNCTION
#undef VULKAN_INSTANCE_FUNCTION
}

static void createInstance(void)
{
    VkApplicationInfo appInfo = { 0 };
    VkInstanceCreateInfo instanceCreateInfo = { 0 };
    VkResult result;

    appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appInfo.apiVersion = VK_API_VERSION_1_0;
    instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    instanceCreateInfo.pApplicationInfo = &appInfo;
#ifdef __APPLE__
    // Allocate our own extension array so that we can add the KHR_portability extensions for MoltenVK
    SDL_Vulkan_GetInstanceExtensions(&instanceCreateInfo.enabledExtensionCount);
    instanceCreateInfo.ppEnabledExtensionNames = SDL_stack_alloc(char**, instanceCreateInfo.enabledExtensionCount + 1);
    const char* const* sdlExtensions = SDL_Vulkan_GetInstanceExtensions(&instanceCreateInfo.enabledExtensionCount);
    SDL_memcpy(instanceCreateInfo.ppEnabledExtensionNames, sdlExtensions, sizeof(const char* const*) * instanceCreateInfo.enabledExtensionCount);
    instanceCreateInfo.ppEnabledExtensionNames[instanceCreateInfo.enabledExtensionCount++] = "VK_KHR_portability_enumeration";

    instanceCreateInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
#else
    instanceCreateInfo.ppEnabledExtensionNames = SDL_Vulkan_GetInstanceExtensions(&instanceCreateInfo.enabledExtensionCount);
#endif

    result = vkCreateInstance(&instanceCreateInfo, NULL, &vulkanContext->instance);

#ifdef __APPLE__
    SDL_stack_free(instanceCreateInfo.ppEnabledExtensionNames);
#endif

    if (result != VK_SUCCESS) {
        vulkanContext->instance = VK_NULL_HANDLE;
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                     "vkCreateInstance(): %s",
                     getVulkanResultString(result));
        quit(2);
    }
}

static void loadInstanceFunctions(void)
{

Review comment (suggestion):
```suggestion
    const char* const* sdlExtensions = SDL_Vulkan_GetInstanceExtensions(&instanceCreateInfo.enabledExtensionCount);
    instanceCreateInfo.ppEnabledExtensionNames = SDL_stack_alloc(char**, instanceCreateInfo.enabledExtensionCount + 1);
```

Code after:
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,                                   \
                     "vkGetInstanceProcAddr(VK_NULL_HANDLE, \"" #name "\") failed"); \
        quit(2);                                                                     \
    }
#define VULKAN_INSTANCE_FUNCTION(name)
    VULKAN_FUNCTIONS()
#undef VULKAN_DEVICE_FUNCTION
#undef VULKAN_GLOBAL_FUNCTION
#undef VULKAN_INSTANCE_FUNCTION
}

static bool checkVulkanPortability(void)
{
    Uint32 extensionCount, i;
    VkExtensionProperties *availableExtensions;
    bool supported = false;

    vkEnumerateInstanceExtensionProperties(
        NULL,
        &extensionCount,
        NULL);
    availableExtensions = SDL_malloc(
        extensionCount * sizeof(VkExtensionProperties));
    vkEnumerateInstanceExtensionProperties(
        NULL,
        &extensionCount,
        availableExtensions);

    for (i = 0; i < extensionCount; i += 1) {
        if (SDL_strcmp(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, availableExtensions[i].extensionName) == 0) {
            supported = true;
            break;
        }
    }

    SDL_free(availableExtensions);
    return supported;
}

static void createInstance(void)
{
    VkApplicationInfo appInfo = { 0 };
    VkInstanceCreateInfo instanceCreateInfo = { 0 };
    bool supportsPortabilityEnumeration;
    const char **instanceExtensions;
    VkResult result;

    appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    appInfo.apiVersion = VK_API_VERSION_1_0;
    instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    instanceCreateInfo.pApplicationInfo = &appInfo;