From 17d1aba905c91a4a6ddadb4625aff67f12bb7ea6 Mon Sep 17 00:00:00 2001 From: DepressedTWM Date: Mon, 1 Jun 2026 10:01:31 -0400 Subject: [PATCH] crash() rework --- src/meow.cpp | 21 ++++++++++++++------- src/meow.h | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/meow.cpp b/src/meow.cpp index 2e2b6b9..930506f 100644 --- a/src/meow.cpp +++ b/src/meow.cpp @@ -40,9 +40,19 @@ static inline const char* glGetStringInt(GLenum name){ return (const char*) gl.GetString(name); } -void crash(const char* reason, Exception::Type t, bool do_exp){ +void crash(Exception::Type t, const char *fmt, ...){ char msg[1024]; - SDL_snprintf(msg, sizeof msg, "Error occured! Error message: %s\n\n Want to create a crash log? You can share the crash log with the developers and help resolve the issue.", reason); + va_list args; + va_start(args, fmt); + va_list args_copy; + va_copy(args_copy, args); + short len = SDL_vsnprintf(NULL, 0, fmt, args_copy); + va_end(args_copy); + char *buf = SDL_malloc((size_t)len + 1); + SDL_vsnprintf(buf, (size_t)len + 1, fmt, args); + va_end(args); + + SDL_snprintf(msg, sizeof msg, "Error occured! Error message: %s\n\n Want to create a crash log? You can share the crash log with the developers and help resolve the issue.", buf); SDL_MessageBoxData messageboxdata = { .flags = SDL_MESSAGEBOX_ERROR, .window = NULL, @@ -53,7 +63,6 @@ void crash(const char* reason, Exception::Type t, bool do_exp){ .colorScheme = NULL }; - int buttonid = 0; if (SDL_ShowMessageBox(&messageboxdata, &buttonid) == false) { printf("[CRASHDUMP] %s\n", reason); @@ -109,10 +118,8 @@ void crash(const char* reason, Exception::Type t, bool do_exp){ } } - if(do_exp == true){ - if(!t == Exception::MEOW) - throw Exception(t, msg); - } + if(!t == Exception::MEOW) + throw Exception(t, msg); } diff --git a/src/meow.h b/src/meow.h index 53afde0..0f3ed7c 100644 --- a/src/meow.h +++ b/src/meow.h @@ -1,4 +1,4 @@ #include "exception.h" -void crash(const char* reason, Exception::Type t, bool do_exp); +void crash(Exception::Type t, const char *fmt, ...); void ErrorMsg(const char* message); void WarnMsg(const char* message);