Kohi Game Engine
asserts.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 #ifdef KASSERTIONS_ENABLED
21 #if _MSC_VER
22 #include <intrin.h>
24 #define debugBreak() __debugbreak()
25 #else
27 #define debugBreak() __builtin_trap()
28 #endif
29 
38 KAPI void report_assertion_failure(const char* expression, const char* message, const char* file, i32 line);
39 
45 #define KASSERT(expr) \
46  { \
47  if (expr) { \
48  } else { \
49  report_assertion_failure(#expr, "", __FILE__, __LINE__); \
50  debugBreak(); \
51  } \
52  }
53 
61 #define KASSERT_MSG(expr, message) \
62  { \
63  if (expr) { \
64  } else { \
65  report_assertion_failure(#expr, message, __FILE__, __LINE__); \
66  debugBreak(); \
67  } \
68  }
69 
70 #ifdef _DEBUG
77 #define KASSERT_DEBUG(expr) \
78  { \
79  if (expr) { \
80  } else { \
81  report_assertion_failure(#expr, "", __FILE__, __LINE__); \
82  debugBreak(); \
83  } \
84  }
85 #else
86 #define KASSERT_DEBUG(expr) // Does nothing at all
87 #endif
88 
89 #else
90 #define KASSERT(expr) // Does nothing at all
91 #define KASSERT_MSG(expr, message) // Does nothing at all
92 #define KASSERT_DEBUG(expr) // Does nothing at all
93 #endif
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...
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:177
signed int i32
Signed 32-bit integer.
Definition: defines.h:39