2024-05-15 11:33:45 +02:00
|
|
|
#ifndef TOOLS_H_INCLUDE
|
|
|
|
#define TOOLS_H_INCLUDE
|
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
#define INTERNAL_BUILD 1
|
2024-05-15 11:33:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <csignal>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
|
|
|
|
#ifdef PLATFORM_WIN32
|
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
inline void assertFuncProduction(
|
|
|
|
const char *expression,
|
|
|
|
const char *file_name,
|
|
|
|
unsigned const line_number,
|
|
|
|
const char *comment = "---")
|
2024-05-15 11:33:45 +02:00
|
|
|
{
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
char c[1024] = {};
|
|
|
|
|
|
|
|
sprintf(c,
|
|
|
|
"Assertion failed\n\n"
|
|
|
|
"File:\n"
|
|
|
|
"%s\n\n"
|
|
|
|
"Line:\n"
|
|
|
|
"%u\n\n"
|
|
|
|
"Expresion:\n"
|
|
|
|
"%s\n\n"
|
|
|
|
"Comment:\n"
|
|
|
|
"%s"
|
|
|
|
"\n\nPlease report this error to the developer.",
|
|
|
|
file_name,
|
|
|
|
line_number,
|
|
|
|
expression,
|
|
|
|
comment
|
|
|
|
);
|
|
|
|
|
|
|
|
int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL
|
|
|
|
| MB_ICONHAND | MB_OK | MB_SETFOREGROUND);
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
{
|
|
|
|
raise(SIGABRT);
|
|
|
|
_exit(3);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
_exit(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 11:33:45 +02:00
|
|
|
}
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
inline void assertFuncInternal(
|
|
|
|
const char *expression,
|
|
|
|
const char *file_name,
|
|
|
|
unsigned const line_number,
|
|
|
|
const char *comment = "---")
|
2024-05-15 11:33:45 +02:00
|
|
|
{
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
char c[1024] = {};
|
|
|
|
|
|
|
|
sprintf(c,
|
|
|
|
"Assertion failed\n\n"
|
|
|
|
"File:\n"
|
|
|
|
"%s\n\n"
|
|
|
|
"Line:\n"
|
|
|
|
"%u\n\n"
|
|
|
|
"Expresion:\n"
|
|
|
|
"%s\n\n"
|
|
|
|
"Comment:\n"
|
|
|
|
"%s"
|
|
|
|
"\n\nPress retry to debug.",
|
|
|
|
file_name,
|
|
|
|
line_number,
|
|
|
|
expression,
|
|
|
|
comment
|
|
|
|
);
|
|
|
|
|
|
|
|
int const action = MessageBox(0, c, "Platform Layer", MB_TASKMODAL
|
|
|
|
| MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND);
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case IDABORT:
|
|
|
|
{
|
|
|
|
raise(SIGABRT);
|
|
|
|
_exit(3);
|
|
|
|
}
|
|
|
|
case IDRETRY:
|
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case IDIGNORE:
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 11:33:45 +02:00
|
|
|
}
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
#if INTERNAL_BUILD == 1
|
|
|
|
|
|
|
|
#define permaAssert(expression) (void)( \
|
2024-05-15 11:33:45 +02:00
|
|
|
(!!(expression)) || \
|
|
|
|
(assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
|
|
|
)
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
#define permaAssertComment(expression, comment) (void)( \
|
2024-05-15 11:33:45 +02:00
|
|
|
(!!(expression)) || \
|
|
|
|
(assertFuncInternal(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \
|
|
|
|
)
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define permaAssert(expression) (void)( \
|
2024-05-15 11:33:45 +02:00
|
|
|
(!!(expression)) || \
|
|
|
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
|
|
|
)
|
2024-05-15 12:29:16 +02:00
|
|
|
|
|
|
|
#define permaAssertComment(expression, comment) (void)( \
|
2024-05-15 11:33:45 +02:00
|
|
|
(!!(expression)) || \
|
|
|
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__), comment), 1) \
|
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2024-05-15 11:33:45 +02:00
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
inline void assertFuncProduction(
|
|
|
|
const char *expression,
|
|
|
|
const char *file_name,
|
|
|
|
unsigned const line_number,
|
|
|
|
const char *comment = "---")
|
|
|
|
{
|
2024-05-15 11:33:45 +02:00
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
raise(SIGABRT);
|
|
|
|
|
|
|
|
}
|
2024-05-15 11:33:45 +02:00
|
|
|
|
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
#define permaAssert(expression) (void)( \
|
2024-05-15 11:33:45 +02:00
|
|
|
(!!(expression)) || \
|
|
|
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0) \
|
|
|
|
)
|
|
|
|
|
2024-05-15 12:29:16 +02:00
|
|
|
#define permaAssertComment(expression, comment) (void)( \
|
2024-05-15 11:33:45 +02:00
|
|
|
(!!(expression)) || \
|
|
|
|
(assertFuncProduction(#expression, __FILE__, (unsigned)(__LINE__)), 0, comment) \
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|