fix: debug logs were not appearing + added some useful debug logs + included exit code in error message

This commit is contained in:
2025-03-04 14:57:39 +01:00
parent 1d8a227180
commit a651eab53f
3 changed files with 9 additions and 3 deletions

View File

@@ -26,7 +26,7 @@ gamestatus get_gamestatus(void) {
return status; return status;
} }
void debug(char const* restrict fmt, ...) { void debug(char const* fmt, ...) {
char const* env = getenv("DEBUG"); char const* env = getenv("DEBUG");
if (env == NULL || *env != '1') if (env == NULL || *env != '1')
return; return;
@@ -54,7 +54,7 @@ noreturn void error(gamestatus error_code, char const* fname, uint32_t ln, char
write_args(buf1, fmt); write_args(buf1, fmt);
char buf2[PRINT_BUFFER_SIZE * 2] = {0}; 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); (void)fprintf(stderr, "\033[91mE: %s\033[0m\n", buf2);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf2, NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf2, NULL);

View File

@@ -50,13 +50,17 @@ int32_t main(int32_t argc, char** argv) {
(void)argc, (void)argv; (void)argc, (void)argv;
init(); init();
debug("successfully initialized!");
while (get_gamestatus() == STATUS_RUNNING) while (get_gamestatus() == STATUS_RUNNING)
update(); update();
debug("done! starting to free resources...");
game_free(&gdat); game_free(&gdat);
render_free(&rdat); render_free(&rdat);
SDL_Quit(); SDL_Quit();
return get_gamestatus(); gamestatus exit_code = get_gamestatus();
debug("quitting with an exit code of %u", exit_code);
return exit_code;
} }

View File

@@ -130,6 +130,8 @@ audiodata audio_wav_load(audiodevice const* dev, char const* fpath) {
SDL_AudioSpec spec; SDL_AudioSpec spec;
audiodata audio; audiodata audio;
debug("loading audio file '%s'...", fpath);
// load and parse the audio to the correct format // load and parse the audio to the correct format
SDL_LoadWAV(fpath, &spec, &audio.buf, &audio.len); SDL_LoadWAV(fpath, &spec, &audio.buf, &audio.len);
audio_cvt(dev, &spec, &audio.buf, &audio.len); audio_cvt(dev, &spec, &audio.buf, &audio.len);