Make asserts work better in headless when running tests on Windows

This commit is contained in:
Henrik Rydgård committed 2024-04-16 22:54:48 +02:00
1 parent 5a38a359e9
commit 178147b20a
3 files changed
+16 -4

No files matched your search

+14 -4
View File
@@ -37,9 +37,10 @@
static bool hitAnyAsserts = false;
std::mutex g_extraAssertInfoMutex;
std::string g_extraAssertInfo = "menu";
double g_assertInfoTime = 0.0;
static std::mutex g_extraAssertInfoMutex;
static std::string g_extraAssertInfo = "menu";
static double g_assertInfoTime = 0.0;
static bool g_exitOnAssert;
void SetExtraAssertInfo(const char *info) {
std::lock_guard<std::mutex> guard(g_extraAssertInfoMutex);
@@ -47,6 +48,10 @@ void SetExtraAssertInfo(const char *info) {
g_assertInfoTime = time_now_d();
}
void SetCleanExitOnAssert() {
g_exitOnAssert = true;
}
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...) {
// Read message and write it to the log
char text[LOG_BUF_SIZE];
@@ -78,8 +83,13 @@ bool HandleAssert(const char *function, const char *file, int line, const char *
std::wstring wtext = ConvertUTF8ToWString(formatted) + L"\n\nTry to continue?";
std::wstring wcaption = ConvertUTF8ToWString(std::string(caption) + " " + GetCurrentThreadName());
OutputDebugString(wtext.c_str());
printf("%s\n", formatted);
if (IDYES != MessageBox(0, wtext.c_str(), wcaption.c_str(), msgBoxStyle)) {
return false;
if (g_exitOnAssert) {
// Hard exit.
ExitProcess(1);
return false;
}
} else {
return true;
}