annotate Engine/ErrorHandling.h @ 2553:48708da03b7f

Party Creation UI logic separated from MainMenu
author a.parshin
date Wed, 13 May 2015 02:20:05 +0200
parents b6140dfeac27
children
rev   line source
2543
b6140dfeac27 GameOver h/cpp
a.parshin
parents: 2524
diff changeset
1 #pragma once
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
2 #define _CRT_NON_CONFORMING_SWPRINTFS
2543
b6140dfeac27 GameOver h/cpp
a.parshin
parents: 2524
diff changeset
3 #define _CRT_SECURE_NO_WARNINGS
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
4
2524
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2499
diff changeset
5 #define Error(format, ...) do {Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__); __debugbreak(); exit(0); } while (0)
c7264ab7132f Main menu rendered using d3d11
a.parshin
parents: 2499
diff changeset
6 #define Assert(condition, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, __VA_ARGS__)
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
7
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
8
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
9
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
10 #include <stdarg.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
11 #include <stdio.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
12 inline __declspec(noreturn) void Error_impl_(const char *filename, const char *functionname, int line,
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
13 const char *format, ...)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
14 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
15 va_list va;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
16 va_start(va, format);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
17 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
18 char header[4096];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
19 sprintf(header, "Error in %s: %u\n\t%s\n\n", filename, line, functionname);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
20
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
21 char msg_body[8192];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
22 vsprintf(msg_body, format, va);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
23
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
24 wchar_t msg[sizeof(header) + sizeof(msg_body)];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
25 swprintf(msg, 8192, L"%S %S", header, msg_body);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
26
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
27 extern void MsgBox(const wchar_t *, const wchar_t *);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
28 MsgBox(msg, L"Error");
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
29 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
30 va_end(va);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
31 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
32
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
33
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
34 inline void Assert_impl_(const char *filename, const char *functionname, int line,
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
35 bool condition, const char *condition_string, const char *format = nullptr, ...)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
36 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
37 if (condition)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
38 return;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
39
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
40 va_list va;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
41 va_start(va, format);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
42 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
43 char header[4096];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
44 sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
45
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
46 char msg_body[8192];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
47 vsprintf(msg_body, format, va);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
48
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
49 wchar_t msg[sizeof(header) + sizeof(msg_body)];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
50 if (format)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
51 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S %S", header, msg_body);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
52 else
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
53 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S", header);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
54
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
55 extern void MsgBox(const wchar_t *, const wchar_t *);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
56 MsgBox(msg, L"Assertion");
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
57 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
58 va_end(va);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
59
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
60 __debugbreak();
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
61 }