From 14288e6b15e8c8a61ccfcf859583268529776f11 Mon Sep 17 00:00:00 2001 From: kkard2 Date: Sun, 7 Sep 2025 11:02:24 +0200 Subject: handle some edge cases with 0 sized canvas --- .gitignore | 4 +++- run.bat | 2 +- sponge.h | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ab3b8fd..8ad6369 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.exe *.obj -platform_x11 +*.ilk +*.pdb +*.rdi diff --git a/run.bat b/run.bat index 0eb177d..0ec23a4 100644 --- a/run.bat +++ b/run.bat @@ -1,4 +1,4 @@ del out.exe del *.obj -cl platform_win32.c "examples\%1" user32.lib gdi32.lib /W3 /Fe:out.exe +cl platform_win32.c "examples\%1" user32.lib gdi32.lib /W3 /Fe:out.exe /Z7 out.exe diff --git a/sponge.h b/sponge.h index 5229bd9..b6fb336 100644 --- a/sponge.h +++ b/sponge.h @@ -15,7 +15,13 @@ void sponge_draw_texture(sponge_Texture c, uint32_t x0, uint32_t y0, sponge_Text #ifdef SPONGE_IMPLEMENTATION +int sponge__canvas_valid(sponge_Texture c) { + return c.width != 0 && c.height != 0; +} + void sponge_clear(sponge_Texture c, uint32_t color) { + if (!sponge__canvas_valid(c)) + return; sponge_draw_rect(c, 0, 0, c.width - 1, c.height - 1, color); } @@ -32,6 +38,9 @@ void sponge_draw_rect(sponge_Texture c, uint32_t x0, uint32_t y0, uint32_t x1, u } void sponge_draw_texture(sponge_Texture c, uint32_t x0, uint32_t y0, sponge_Texture tex) { + if (!sponge__canvas_valid(c)) + return; + uint32_t *row_dst = c.pixels + (y0 * c.stride); uint32_t *row_src = tex.pixels; uint32_t x1 = x0 + tex.width; -- cgit v1.3.1