From 4b1e57ac72093ee5b759a5825f9d5a8eb9e2f994 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Fri, 10 Jul 2020 19:00:36 -0500 Subject: [PATCH] More data safety checking, doesn't load spaces. --- .../Graphics/Text/BitmapFont.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs b/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs index 57cba5e..f87d3b9 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs @@ -45,7 +45,12 @@ namespace SlatedGameToolkit.Framework.Graphics.Text public unsafe BitmapFont(byte[] data, GLContext glContext = null, int cacheSize = 1024, int textures = 2, uint textureSizes = 512) { info = new StbTrueType.stbtt_fontinfo(); fixed(byte* dataPtr = &data[0]) { - StbTrueType.stbtt_InitFont(info, dataPtr, 0); + int offset = StbTrueType.stbtt_GetFontOffsetForIndex(dataPtr, 0); + if (offset != -1) { + StbTrueType.stbtt_InitFont(info, dataPtr, offset); + } else { + throw new FrameworkUsageException("Could not load ttf file."); + } } this.glyphIndices = new LRUCache(cacheSize); @@ -90,6 +95,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Text int textureChanges = 0; foreach (char c in characters) { + if (c == ' ') continue; if (!glyphTexLocations.ContainsKey((c, scale)) || !textures[glyphTexLocations[(c, scale)]].ContainsChar(c, scale)) { glyphTexLocations.Remove((c, scale)); if (!textures[drawingTo].Upload(scale, c)) {