From 51a31cc7ea1d2efc0be3b80d0e263d7c2526dc97 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Sat, 6 May 2023 16:34:13 -0700 Subject: [PATCH] Make custom assert work in wasm --- better_assert.h | 10 ++++++++++ codegen.c | 1 + main.c | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/better_assert.h b/better_assert.h index a25c83a..44439eb 100644 --- a/better_assert.h +++ b/better_assert.h @@ -1,11 +1,21 @@ #include +#ifdef WEB +#include +#endif + static inline void assert_impl(bool cond, const char *expression) { if(!cond) { fprintf(stderr, "Assertion failed: %s\n", expression); +#ifdef WEB + assert(false); +#elif defined(DESKTOP) __debugbreak(); +#else +#error "Don't know how to assert for current platform configuration" +#endif } } #ifdef assert diff --git a/codegen.c b/codegen.c index e8f92b0..8ec3228 100644 --- a/codegen.c +++ b/codegen.c @@ -1,5 +1,6 @@ #include #include +#define DESKTOP #include "better_assert.h" #include "buff.h" diff --git a/main.c b/main.c index e38b8ab..3fbde9d 100644 --- a/main.c +++ b/main.c @@ -2,12 +2,18 @@ // you will die someday #define SOKOL_IMPL + #if defined(WIN32) || defined(_WIN32) #define DESKTOP #define WINDOWS #define SOKOL_D3D11 #endif +#if defined(__EMSCRIPTEN__) +#define WEB +#define SOKOL_GLES2 +#endif + #ifdef WINDOWS #include #include @@ -15,6 +21,7 @@ #endif + #include "buff.h" #include "sokol_app.h" #include "sokol_gfx.h"