Saga
Saga Game Engine
Loading...
Searching...
No Matches
asserts.h
Go to the documentation of this file.
1#pragma once
2#include "../defines.h"
3
4namespace Saga {
5
6// Comment the line below to disable assertions
7#define SAGA_ASSERTIONS_ENABLED
8
9#ifdef SAGA_ASSERTIONS_ENABLED
10
11/*
12 We do this so that this is compatible with different compilers. VSCode's MSC will complain if we use builtin_trap, since that's clang specific. But Qt uses builtin_trap
13*/
14#if _MSC_VER
15#include <intrin.h>
19#define debugBreak() __debugbreak()
20#else
21#define debugBreak() __builtin_trap()
22#endif
23
33void reportAssertionFailed(const char *expression, const char *message, const char *file, int line, ...);
34
39#define SASSERT(expr) \
40 { \
41 if (!(expr)) { \
42 reportAssertionFailed(#expr, "", __FILE__, __LINE__); \
43 debugBreak(); \
44 } \
45 }
46
52#define SASSERT_MESSAGE(expr, message, ...) \
53 { \
54 if (!(expr)) { \
55 reportAssertionFailed(#expr, message, __FILE__, __LINE__, ##__VA_ARGS__); \
56 debugBreak(); \
57 } \
58 }
59
60#ifdef SAGA_DEBUG
65#define SASSERT_DEBUG(expr) \
66 { \
67 if (!(expr)) { \
68 reportAssertionFailed(#expr, "", __FILE__, __LINE__); \
69 debugBreak(); \
70 } \
71 }
72
78#define SASSERT_DEBUG_MESSAGE(expr, message, ...) \
79 { \
80 if (!(expr)) { \
81 reportAssertionFailed(#expr, message, __FILE__, __LINE__, ##__VA_ARGS__); \
82 debugBreak(); \
83 } \
84 }
85#else
86#define SASSERT_DEBUG(expr) // does nothing
87#define SASSERT_DEBUG_MESSAGE(expr, message) // does nothing
88#endif
89
90#else
91#define SASSERT(expr) // does nothing
92#define SASSERT(expr, message) // does nothing
93#define SASSERT_DEBUG(expr) // does nothing
94#define SASSERT_DEBUG_MESSAGE(expr, message) // does nothing
95#endif
96
97} // namespace Saga
Definition: app.cpp:8
void reportAssertionFailed(const char *expression, const char *message, const char *file, int line,...)
Output a message signaling that an assertion has failed. This message is of the form: Assertion Failu...
Definition: logger.cpp:10