From a651eab53fb3c68a366b44e6de122f287fffbdfc Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 4 Mar 2025 14:57:39 +0100 Subject: [PATCH] fix: debug logs were not appearing + added some useful debug logs + included exit code in error message --- src/error.c | 4 ++-- src/main.c | 6 +++++- src/window/audio.c | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/error.c b/src/error.c index 0cc817c..f84d282 100644 --- a/src/error.c +++ b/src/error.c @@ -26,7 +26,7 @@ gamestatus get_gamestatus(void) { return status; } -void debug(char const* restrict fmt, ...) { +void debug(char const* fmt, ...) { char const* env = getenv("DEBUG"); if (env == NULL || *env != '1') return; @@ -54,7 +54,7 @@ noreturn void error(gamestatus error_code, char const* fname, uint32_t ln, char write_args(buf1, fmt); char buf2[PRINT_BUFFER_SIZE * 2] = {0}; - sprintf(buf2, "%s\n at %s:%u", buf1, fname, ln); + sprintf(buf2, "%s\n at %s:%u (exitcode: %u)", buf1, fname, ln, error_code); (void)fprintf(stderr, "\033[91mE: %s\033[0m\n", buf2); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf2, NULL); diff --git a/src/main.c b/src/main.c index f20af14..e4243ea 100644 --- a/src/main.c +++ b/src/main.c @@ -50,13 +50,17 @@ int32_t main(int32_t argc, char** argv) { (void)argc, (void)argv; init(); + debug("successfully initialized!"); while (get_gamestatus() == STATUS_RUNNING) update(); + debug("done! starting to free resources..."); game_free(&gdat); render_free(&rdat); SDL_Quit(); - return get_gamestatus(); + gamestatus exit_code = get_gamestatus(); + debug("quitting with an exit code of %u", exit_code); + return exit_code; } diff --git a/src/window/audio.c b/src/window/audio.c index ce472b0..6df6d93 100644 --- a/src/window/audio.c +++ b/src/window/audio.c @@ -130,6 +130,8 @@ audiodata audio_wav_load(audiodevice const* dev, char const* fpath) { SDL_AudioSpec spec; audiodata audio; + debug("loading audio file '%s'...", fpath); + // load and parse the audio to the correct format SDL_LoadWAV(fpath, &spec, &audio.buf, &audio.len); audio_cvt(dev, &spec, &audio.buf, &audio.len);