From 508e9d4ecb69c11db3d693cd3ef37c680715dc38 Mon Sep 17 00:00:00 2001 From: Paolo Mazzon Date: Tue, 23 Jul 2024 11:57:10 -0700 Subject: [PATCH] improved output to error file --- README.md | 4 ++-- VK2D/Renderer.c | 4 +++- VK2D/RendererMeta.c | 2 +- VK2D/Validation.c | 23 +++++++++++++++++++++++ VK2D/Validation.h | 8 +++----- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 04de1f6..bb00419 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ add_executable(... ${VK2D_FILES} ${VMA_FILES}) Vulkan2D also requires the following external dependencies: - SDL2, 2.0+ - Vulkan 1.2+ + SDL2, 2.0.6+ + Vulkan 1.1+ C11 + C standard library C++17 (VMA uses C++17) diff --git a/VK2D/Renderer.c b/VK2D/Renderer.c index 06aebf6..f1d60c1 100644 --- a/VK2D/Renderer.c +++ b/VK2D/Renderer.c @@ -187,6 +187,8 @@ VK2DResult vk2dRendererInit(SDL_Window *window, VK2DRendererConfig config, VK2DS VK_VERSION_PATCH(props.apiVersion) ); + vk2dValidationWriteHeader(); + // Assign user settings, except for screen mode which will be handled later gRenderer->config = config; gRenderer->config.msaa = gRenderer->limits.maxMSAA >= config.msaa ? config.msaa : gRenderer->limits.maxMSAA; @@ -204,7 +206,7 @@ VK2DResult vk2dRendererInit(SDL_Window *window, VK2DRendererConfig config, VK2DS allocatorCreateInfo.vulkanApiVersion = VK_MAKE_VERSION(1, 1, 0); result = vmaCreateAllocator(&allocatorCreateInfo, &gRenderer->vma); if (result != VK_SUCCESS) { - vk2dRaise(0, "\nFailed to initialize VMA, Vulkan error %i.", result); + vk2dRaise(VK2D_STATUS_VULKAN_ERROR, "\nFailed to initialize VMA, Vulkan error %i.", result); vk2dRendererQuit(); return VK2D_ERROR; } diff --git a/VK2D/RendererMeta.c b/VK2D/RendererMeta.c index 1d35ebf..1cc8c49 100644 --- a/VK2D/RendererMeta.c +++ b/VK2D/RendererMeta.c @@ -276,7 +276,7 @@ void _vk2dRendererCreateDebug() { void _vk2dRendererDestroyDebug() { VK2DRenderer gRenderer = vk2dRendererGetPointer(); - if (gRenderer->options.enableDebug) { + if (gRenderer->options.enableDebug && gRenderer->dr != NULL) { fvkDestroyDebugReportCallbackEXT(gRenderer->vk, gRenderer->dr, VK_NULL_HANDLE); } } diff --git a/VK2D/Validation.c b/VK2D/Validation.c index 223132e..4bb5a52 100644 --- a/VK2D/Validation.c +++ b/VK2D/Validation.c @@ -2,6 +2,7 @@ /// \author Paolo Mazzon #include "VK2D/Validation.h" #include +#include #include #include #include @@ -27,9 +28,30 @@ void vk2dValidationBegin(const char *errorFile, bool quitOnError) { } void vk2dValidationEnd() { + if (gErrorFile != NULL) { + FILE *f = fopen(gErrorFile, "a"); + if (f != NULL) { + fprintf(f, "------END------\n"); + fclose(f); + } + } + SDL_DestroyMutex(gLogMutex); } +void vk2dValidationWriteHeader() { + VK2DRenderer gRenderer = vk2dRendererGetPointer(); + + if (gErrorFile != NULL) { + FILE *f = fopen(gErrorFile, "a"); + if (f != NULL) { + time_t t = time(NULL); + fprintf(f, "------START------\n%s%s", ctime(&t), vk2dHostInformation()); + fclose(f); + } + } +} + // Safe string length method static int32_t stringLength(const char *str, int32_t size) { int32_t len = 0; @@ -66,6 +88,7 @@ void vk2dRaise(VK2DStatus result, const char* fmt, ...) { if (gErrorFile != NULL) { FILE *f = fopen(gErrorFile, "a"); if (f != NULL) { + fprintf(f, "[VK2D Status %i] ", gStatus); va_start(list, fmt); vfprintf(f, fmt, list); fprintf(f, "\n"); diff --git a/VK2D/Validation.h b/VK2D/Validation.h index 8565a39..c4bf5fc 100644 --- a/VK2D/Validation.h +++ b/VK2D/Validation.h @@ -10,11 +10,6 @@ extern "C" { #endif -// For debug only -//#define vk2dPointerCheck(ptr) (ptr) -//#define vk2dErrorCheck(e) (e); -//#define vk2dErrorInline(ptr) ((ptr) == VK_SUCCESS) - /// \brief Prints a log message if VKRE_VERBOSE_STDOUT is enabled void vk2dLog(const char* fmt, ...); @@ -33,6 +28,9 @@ void vk2dValidationBegin(const char *errorFile, bool quitOnError); /// \brief Cleans up validation synchronization primitives void vk2dValidationEnd(); +/// \brief Writes a header to the error file (if there is one) at the start of the program +void vk2dValidationWriteHeader(); + /// \brief Used internally to handle debugging callbacks VKAPI_ATTR VkBool32 VKAPI_CALL _vk2dDebugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t sourceObject, size_t location, int32_t messageCode, const char* layerPrefix, const char* message, void* data);