2543
|
1 #pragma once
|
2499
|
2 #define _CRT_NON_CONFORMING_SWPRINTFS
|
2543
|
3 #define _CRT_SECURE_NO_WARNINGS
|
2499
|
4
|
2524
|
5 #define Error(format, ...) do {Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__); __debugbreak(); exit(0); } while (0)
|
|
6 #define Assert(condition, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, __VA_ARGS__)
|
2499
|
7
|
|
8
|
|
9
|
|
10 #include <stdarg.h>
|
|
11 #include <stdio.h>
|
|
12 inline __declspec(noreturn) void Error_impl_(const char *filename, const char *functionname, int line,
|
|
13 const char *format, ...)
|
|
14 {
|
|
15 va_list va;
|
|
16 va_start(va, format);
|
|
17 {
|
|
18 char header[4096];
|
|
19 sprintf(header, "Error in %s: %u\n\t%s\n\n", filename, line, functionname);
|
|
20
|
|
21 char msg_body[8192];
|
|
22 vsprintf(msg_body, format, va);
|
|
23
|
|
24 wchar_t msg[sizeof(header) + sizeof(msg_body)];
|
|
25 swprintf(msg, 8192, L"%S %S", header, msg_body);
|
|
26
|
|
27 extern void MsgBox(const wchar_t *, const wchar_t *);
|
|
28 MsgBox(msg, L"Error");
|
|
29 }
|
|
30 va_end(va);
|
|
31 }
|
|
32
|
|
33
|
|
34 inline void Assert_impl_(const char *filename, const char *functionname, int line,
|
|
35 bool condition, const char *condition_string, const char *format = nullptr, ...)
|
|
36 {
|
|
37 if (condition)
|
|
38 return;
|
|
39
|
|
40 va_list va;
|
|
41 va_start(va, format);
|
|
42 {
|
|
43 char header[4096];
|
|
44 sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string);
|
|
45
|
|
46 char msg_body[8192];
|
|
47 vsprintf(msg_body, format, va);
|
|
48
|
|
49 wchar_t msg[sizeof(header) + sizeof(msg_body)];
|
|
50 if (format)
|
|
51 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S %S", header, msg_body);
|
|
52 else
|
|
53 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S", header);
|
|
54
|
|
55 extern void MsgBox(const wchar_t *, const wchar_t *);
|
|
56 MsgBox(msg, L"Assertion");
|
|
57 }
|
|
58 va_end(va);
|
|
59
|
|
60 __debugbreak();
|
|
61 } |