Skip to content

Commit

Permalink
improved output to error file
Browse files Browse the repository at this point in the history
  • Loading branch information
PaoloMazzon committed Jul 23, 2024
1 parent eb8009e commit 508e9d4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion VK2D/Renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion VK2D/RendererMeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
23 changes: 23 additions & 0 deletions VK2D/Validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// \author Paolo Mazzon
#include "VK2D/Validation.h"
#include <stdio.h>
#include <time.h>
#include <inttypes.h>
#include <stdarg.h>
#include <assert.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 3 additions & 5 deletions VK2D/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);

Expand All @@ -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);

Expand Down

0 comments on commit 508e9d4

Please sign in to comment.