-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil-err.cpp
More file actions
71 lines (54 loc) · 1.36 KB
/
util-err.cpp
File metadata and controls
71 lines (54 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "util.h"
#if ENABLE_WARNINGS
namespace util
{
# ifdef _DEBUG
bool g_breakOnWarning = true;
# else
bool g_breakOnWarning = false;
# endif
}
#endif // ENABLE_WARNINGS
#if ENABLE_ERRORS
# include <cstdio>
# include <ctime>
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
namespace util
{
# ifdef _DEBUG
bool g_breakOnError = true;
# else
bool g_breakOnError = false;
# endif
static void DefaultErrorCallback(const char * message);
ErrorCallback g_errorCallback = &DefaultErrorCallback;
void error(const char * file, int line, const char * fmt, ...)
{
va_list args;
va_start(args, fmt);
errorva(file, line, fmt, args);
}
void errorva(const char * file, int line, const char * fmt, va_list args)
{
// Always log the message
logva(file, line, fmt, args);
// If not debug-breaking, also send it to the callback
if (g_errorCallback && !g_breakOnError)
{
// Printf the message first, to a fixed-size buffer for simplicity
char message[1024];
vsprintf_s(message, fmt, args);
// Prepend source location
char message2[1024];
sprintf_s(message2, "[%s:%d] %s", file, line, message);
g_errorCallback(message2);
}
}
static void DefaultErrorCallback(const char * message)
{
MessageBoxA(nullptr, message, "Error", MB_ICONEXCLAMATION);
}
}
#endif // ENABLE_ERRORS