Kohi Game Engine
kassert.h
Go to the documentation of this file.
1
13
#pragma once
14
15
#include "
defines.h
"
16
17
// Disable assertions by commenting out the below line.
18
#define KASSERTIONS_ENABLED
19
20
// Always define kdebug_break in case it is ever needed outside assertions (i.e fatal log errors)
21
// Try via __has_builtin first.
22
#if defined(__has_builtin) && !defined(__ibmxl__)
23
# if __has_builtin(__builtin_debugtrap)
24
# define kdebug_break() __builtin_debugtrap()
25
# elif __has_builtin(__debugbreak)
26
# define kdebug_break() __debugbreak()
27
# endif
28
#endif
29
30
// If not setup, try the old way.
31
#if !defined(kdebug_break)
32
# if defined(__clang__) || defined(__gcc__)
34
# define kdebug_break() __builtin_trap()
35
# elif defined(_MSC_VER)
36
# include <intrin.h>
38
# define kdebug_break() __debugbreak()
39
# else
40
// Fall back to x86/x86_64
41
# define kdebug_break() asm { int 3 }
42
# endif
43
#endif
44
45
#ifdef KASSERTIONS_ENABLED
54
KAPI
void
report_assertion_failure
(
const
char
* expression,
const
char
* message,
const
char
* file,
i32
line);
55
61
# define KASSERT(expr) \
62
{ \
63
if (expr) { \
64
} else { \
65
report_assertion_failure(#expr, ""
, __FILE__, __LINE__); \
66
kdebug_break(); \
67
} \
68
}
69
77
# define KASSERT_MSG(expr, message) \
78
{ \
79
if (expr) { \
80
} else { \
81
report_assertion_failure(#expr, message, __FILE__, __LINE__); \
82
kdebug_break(); \
83
} \
84
}
85
86
# if KOHI_DEBUG
93
# define KASSERT_DEBUG(expr) \
94
{ \
95
if (expr) { \
96
} else { \
97
report_assertion_failure(#expr, ""
, __FILE__, __LINE__); \
98
kdebug_break(); \
99
} \
100
}
101
# else
102
# define KASSERT_DEBUG(expr)
// Does nothing at all
103
# endif
104
105
#else
106
# define KASSERT(expr)
// Does nothing at all
107
# define KASSERT_MSG(expr, message)
// Does nothing at all
108
# define KASSERT_DEBUG(expr)
// Does nothing at all
109
#endif
defines.h
This file contains global type definitions which are used throughout the entire engine and applicatio...
KAPI
#define KAPI
Import/export qualifier.
Definition:
defines.h:205
i32
signed int i32
Signed 32-bit integer.
Definition:
defines.h:39
report_assertion_failure
KAPI void report_assertion_failure(const char *expression, const char *message, const char *file, i32 line)
Reports an assertion failure. Note that this is not the assertion itself, just a reporting of an asse...
kohi.core
src
debug
kassert.h
Generated by
1.9.1