diff --git a/main.c b/main.c index b621421..9df3d27 100644 --- a/main.c +++ b/main.c @@ -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 + +#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) diff --git a/utility.h b/utility.h index 6e59483..dc00fab 100644 --- a/utility.h +++ b/utility.h @@ -4,29 +4,43 @@ #include #ifdef WEB -//#include #include -#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__); } \ No newline at end of file +#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }