mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
fix: debug logs were not appearing + added some useful debug logs + included exit code in error message
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user