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