Use one custom assert for all code

main
Phillip Trudeau-Tavara 1 year ago
parent c3a4445dcd
commit c054ecbfa9

@ -28,6 +28,12 @@
#define SOKOL_GLES2
#endif
#define DRWAV_ASSERT game_assert
#define SOKOL_ASSERT game_assert
#define STBDS_ASSERT game_assert
#define STBI_ASSERT game_assert
#define STBTT_assert game_assert
#include "utility.h"
#ifdef WINDOWS
@ -67,11 +73,14 @@ __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = 0x00000001
#pragma warning(pop)
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
#define STB_DS_IMPLEMENTATION
#include "stb_ds.h"
#include "HandmadeMath.h"
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#define STB_DS_IMPLEMENTATION
#include "stb_ds.h" // placed last because it includes <assert.h>
#undef assert
#define assert game_assert
#pragma warning(pop)
@ -179,6 +188,8 @@ void web_arena_set_auto_align(WebArena *arena, size_t align)
#define STBSP_ADD_TO_FUNCTIONS no_ubsan
#define MD_FUNCTION no_ubsan
#include "md.h"
#undef MD_Assert
#define MD_Assert assert
#include "md.c"
#pragma warning(pop)

@ -4,29 +4,43 @@
#include <stdbool.h>
#ifdef WEB
//#include <assert.h>
#include <signal.h>
#endif
#define game_debugbreak() raise(SIGTRAP)
#define game_assert_4127_push
#define game_assert_4127_pop
static void assert_impl(bool cond, const char *expression)
{
if(!cond)
{
fprintf(stderr, "Assertion failed: %s\n", expression);
#ifdef WEB
raise(SIGTRAP);
//assert(false);
#elif defined(DESKTOP)
__debugbreak();
#define game_debugbreak() __debugbreak()
#define game_assert_4127_push __pragma(warning(push)) __pragma(warning(disable:4127))
#define game_assert_4127_pop __pragma(warning(pop))
#else
#error "Don't know how to assert for current platform configuration"
#define game_debugbreak() (void)(0)
#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
#define game_assert(cond) game_assert_4127_push do { (void)0; } while (0) game_assert_4127_pop
#else
#define game_assert(cond) game_assert_4127_push do { \
if (!(cond)) { \
assert_impl(__func__, __FILE__, __LINE__, #cond); \
game_debugbreak(); \
} \
} while (0) game_assert_4127_pop
#endif
#ifdef assert
#undef assert
#endif
#define assert game_assert
#define assert(cond) assert_impl(cond, #cond)
#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }
#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }

Loading…
Cancel
Save