diff --git a/src/base/system.cpp b/src/base/system.cpp index 47528f825..1f4059860 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -169,6 +169,7 @@ static NETSOCKET_INTERNAL invalid_socket = {NETTYPE_INVALID, -1, -1, -1}; #define AF_WEBSOCKET_INET (0xee) std::atomic_bool dbg_assert_failing = false; +DBG_ASSERT_HANDLER dbg_assert_handler; bool dbg_assert_has_failed() { @@ -179,8 +180,17 @@ void dbg_assert_imp(const char *filename, int line, int test, const char *msg) { if(!test) { + const bool already_failing = dbg_assert_has_failed(); dbg_assert_failing.store(true, std::memory_order_release); - dbg_msg("assert", "%s(%d): %s", filename, line, msg); + char error[256]; + str_format(error, sizeof(error), "%s(%d): %s", filename, line, msg); + dbg_msg("assert", "%s", error); + if(!already_failing) + { + DBG_ASSERT_HANDLER handler = dbg_assert_handler; + if(handler) + handler(error); + } log_global_logger_finish(); dbg_break(); } @@ -195,6 +205,11 @@ void dbg_break() #endif } +void dbg_assert_set_handler(DBG_ASSERT_HANDLER handler) +{ + dbg_assert_handler = std::move(handler); +} + void dbg_msg(const char *sys, const char *fmt, ...) { va_list args; diff --git a/src/base/system.h b/src/base/system.h index 765c822f4..7a6b1e5f3 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -108,6 +108,9 @@ bool dbg_assert_has_failed(); void dbg_break(); +typedef std::function DBG_ASSERT_HANDLER; +void dbg_assert_set_handler(DBG_ASSERT_HANDLER handler); + /** * Prints a debug message. * diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index f769d4c82..ee7381940 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -4534,6 +4534,7 @@ int main(int argc, const char **argv) CWindowsComLifecycle WindowsComLifecycle(true); #endif CCmdlineFix CmdlineFix(&argc, &argv); + bool Silent = false; bool RandInitFailed = false; @@ -4582,6 +4583,12 @@ int main(int argc, const char **argv) pKernel->RegisterInterface(pClient, false); pClient->RegisterInterfaces(); + dbg_assert_set_handler([pClient](const char *pMsg) { + char aMessage[256]; + str_format(aMessage, sizeof(aMessage), "An assertion error occured. Please write down or take a screenshot of the following information and report this error.\n\n%s", pMsg); + pClient->ShowMessageBox("Assertion Error", aMessage); + }); + // create the components IEngine *pEngine = CreateEngine(GAME_NAME, pFutureConsoleLogger, 2); IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT).release();