From 0ffd63fed9dcfb60be7378b6f53f0f1d011fd26c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 24 May 2025 17:01:01 -0700 Subject: Tweaks --- font/font.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'font/font.h') diff --git a/font/font.h b/font/font.h index 13ff1c3..9d37e64 100644 --- a/font/font.h +++ b/font/font.h @@ -5,7 +5,7 @@ static const unsigned char FontGlyphStart = 32; // Space. static const unsigned char FontGlyphEnd = 127; // One past tilde. -static const int FontAtlasNumGlyphs = FontGlyphEnd - FontGlyphStart; +static const unsigned int FontAtlasNumGlyphs = FontGlyphEnd - FontGlyphStart; /// Font atlas header. typedef struct FontHeader { @@ -32,8 +32,10 @@ FontAtlas* LoadFontAtlas(const char* path); static inline const unsigned char* FontGetGlyph( const FontAtlas* atlas, unsigned char c) { assert(atlas); - const int index = c - FontGlyphStart; - assert(index >= 0); + unsigned index = c - FontGlyphStart; + if (index >= FontAtlasNumGlyphs) { + index = '?' - FontGlyphStart; + } assert(index < FontAtlasNumGlyphs); return atlas->pixels + index * (atlas->header.glyph_width * atlas->header.glyph_height); -- cgit v1.2.3