More data safety checking, doesn't load spaces.

This commit is contained in:
Harrison Deng 2020-07-10 19:00:36 -05:00
parent f4aa9b7ffb
commit 4b1e57ac72

View File

@ -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<char, int>(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)) {