diff options
author | Jordan Halase <jordan@halase.me> | 2019-10-28 19:56:33 -0500 |
---|---|---|
committer | Jordan Halase <jordan@halase.me> | 2019-10-28 19:56:33 -0500 |
commit | f36940f72838eacd7fe6fac627f0855620519a62 (patch) | |
tree | 234b2df2f0363b746939d20f320bfd026eb49371 | |
parent | 56a010b06547b7d414185dbd2532ce209226078c (diff) |
Make code easier
-rw-r--r-- | main.c | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -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; |