From d9c15249e6a92fe92f741610b9fdb0c8d012e722 Mon Sep 17 00:00:00 2001
From: Jordan Halase <jordan@halase.me>
Date: Tue, 29 Oct 2019 21:40:16 -0500
Subject: Fix memory leak and add check for swapchain support

---
 main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/main.c b/main.c
index bc1c36a..dde113a 100644
--- a/main.c
+++ b/main.c
@@ -575,8 +575,26 @@ static int isDeviceSuitable(const struct RenderVulkan *const vk,
 			if (canSurface) break;
 		}
 	}
+	free(queueProperties);
 	if (g >= nQueueFamilies) {
 		/* We only support graphics and present on the same queue family. */
+		printf("No graphics+support queue families found on this device\n");
+		return 0;
+	}
+	VkBool32 canSwapchain = 0;
+	uint32_t nExtensions;
+	vk->api->vkEnumerateDeviceExtensionProperties(pd, NULL, &nExtensions, NULL);
+	VkExtensionProperties *availableExtensions = malloc(nExtensions * sizeof(*availableExtensions));
+	vk->api->vkEnumerateDeviceExtensionProperties(pd, NULL, &nExtensions, availableExtensions);
+	for (uint32_t i = 0; i < nExtensions; ++i) {
+		if (!strcmp(availableExtensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
+			canSwapchain = 1;
+			break;
+		}
+	}
+	free(availableExtensions);
+	if (!canSwapchain) {
+		printf("Cannot use a swapchain on this device\n");
 		return 0;
 	}
 	*graphicsIndex = g;
-- 
cgit v1.2.3