From f36940f72838eacd7fe6fac627f0855620519a62 Mon Sep 17 00:00:00 2001 From: Jordan Halase Date: Mon, 28 Oct 2019 19:56:33 -0500 Subject: Make code easier --- main.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 911e5d7..0d479b8 100644 --- a/main.c +++ b/main.c @@ -86,15 +86,11 @@ struct RenderVulkan { VkDevice device; }; -struct RenderVulkan *vk; - #define ERRMSG_LEN 4096 void setErrMsg(struct RenderVulkan *vk, const char *fmt, ...) { - if (!vk->errMsg) { - vk->errMsg = calloc(1, ERRMSG_LEN); - } + vk->errMsg = realloc(vk->errMsg, ERRMSG_LEN); va_list args; va_start(args, fmt); stbsp_vsnprintf(vk->errMsg, ERRMSG_LEN, fmt, args); @@ -531,24 +527,26 @@ done: free(devices); } -int main() +void rvkCheckFatal(struct RenderVulkan *vk) { const char *errMsg = NULL; - struct RenderVulkan *vk = renderVulkanCreate(); if ((errMsg = getErrMsg(vk))) { fprintf(stderr, "%s\n", errMsg); renderVulkanDestroy(vk); - return 1; + exit(1); } +} + +int main() +{ + const char *errMsg = NULL; + struct RenderVulkan *vk = renderVulkanCreate(); + rvkCheckFatal(vk); printf("Created Vulkan Instance Successfully\n"); selectPhysicalDevice(vk); - if ((errMsg = getErrMsg(vk))) { - fprintf(stderr, "%s\n", errMsg); - renderVulkanDestroy(vk); - return 1; - } + rvkCheckFatal(vk); renderVulkanDestroy(vk); return 0; -- cgit v1.2.1