comparison Engine/ErrorHandling.h @ 2499:68cdef6879a0

engine folder
author Ritor1
date Fri, 19 Sep 2014 02:57:42 +0600
parents
children c7264ab7132f
comparison
equal deleted inserted replaced
2498:92eeeb5200f2 2499:68cdef6879a0
1 #define _CRT_NON_CONFORMING_SWPRINTFS
2 #pragma once
3
4 #define Error(format, ...) Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__)
5 #define Assert(condition, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, __VA_ARGS__)
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 #ifndef NODEBUG
32 __debugbreak();
33 #endif
34 exit(0);
35 }
36
37
38 inline void Assert_impl_(const char *filename, const char *functionname, int line,
39 bool condition, const char *condition_string, const char *format = nullptr, ...)
40 {
41 if (condition)
42 return;
43
44 va_list va;
45 va_start(va, format);
46 {
47 char header[4096];
48 sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string);
49
50 char msg_body[8192];
51 vsprintf(msg_body, format, va);
52
53 wchar_t msg[sizeof(header) + sizeof(msg_body)];
54 if (format)
55 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S %S", header, msg_body);
56 else
57 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S", header);
58
59 extern void MsgBox(const wchar_t *, const wchar_t *);
60 MsgBox(msg, L"Assertion");
61 }
62 va_end(va);
63
64 __debugbreak();
65 }