Greatly improve & simplify assertions

main
Phillip Trudeau-Tavara 1 year ago
parent d5cf3d9f90
commit 68cdbaac08

@ -53,9 +53,6 @@ __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = 0x00000001
#endif #endif
#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x
#include "buff.h" #include "buff.h"
#include "sokol_app.h" #include "sokol_app.h"
#pragma warning(push) #pragma warning(push)

@ -1,43 +1,24 @@
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#ifdef WEB #define STRINGIZE(x) STRINGIZE2(x)
#include <signal.h> #define STRINGIZE2(x) #x
#define game_debugbreak() raise(SIGTRAP)
#define game_assert_4127_push
#define game_assert_4127_pop
#ifdef WEB
#define assert_impl(cond, str) ((cond) || (EM_ASM({ assert(0, UTF8ToString($0) + UTF8ToString($1)); }, (__func__), (str)), 0))
#elif defined(DESKTOP) #elif defined(DESKTOP)
#define game_debugbreak() __debugbreak() #define assert_impl(cond, str) ((cond) || (fputs("Assertion failed: " __FUNCTION__ str "\n", stderr), __debugbreak(), 0))
#define game_assert_4127_push __pragma(warning(push)) __pragma(warning(disable:4127))
#define game_assert_4127_pop __pragma(warning(pop))
#else #else
#error "Don't know how to assert for current platform configuration" #error "Don't know how to assert for current platform configuration"
#define game_debugbreak() (void)(0)
#endif #endif
static void assert_impl(const char *func, const char *file, long line, const char *expression)
{
fprintf(stderr, "Assert fail in %s(%s:%ld):\n \"%s\"\n", func, file, line, expression);
}
#ifdef NDEBUG #ifdef NDEBUG
#define game_assert(cond) game_assert_4127_push do { (void)0; } while (0) game_assert_4127_pop #define game_assert(cond) ((void)0)
#else #else
#define game_assert(cond) game_assert_4127_push do { \ #define game_assert(cond) assert_impl(cond, "(" __FILE__ ":" STRINGIZE(__LINE__) "): \"" #cond "\"")
if (!(cond)) { \
assert_impl(__func__, __FILE__, __LINE__, #cond); \
game_debugbreak(); \
} \
} while (0) game_assert_4127_pop
#endif #endif
#ifdef assert #ifdef assert
#undef assert #undef assert
#endif #endif

Loading…
Cancel
Save