Resolves ArgmentNulLException When Loading BitmapFont From Disk. (#924)

* Correctly swap rayNear and rayFar distance

* Retrieve bmfFile.Path when reading from stream
This closes #923

* Return null if character not found.
This is used for line feed characters.S
This commit is contained in:
Christopher Whitley
2024-07-11 22:24:34 -04:00
committed by GitHub
parent f1fbf9c4b8
commit 3ca0a3ef2a
2 changed files with 4 additions and 2 deletions
@@ -38,7 +38,7 @@ public sealed class BitmapFont
}
}
public BitmapFontCharacter GetCharacter(int character) => _characters[character];
public BitmapFontCharacter GetCharacter(int character) => _characters.TryGetValue(character, out BitmapFontCharacter fontCharacter) ? fontCharacter : null;/* _characters[character];*/
public bool TryGetCharacter(int character, out BitmapFontCharacter value) => _characters.TryGetValue(character, out value);
public SizeF MeasureString(string text)
@@ -378,7 +378,7 @@ public sealed class BitmapFont
{
if (!pages.ContainsKey(bmfFile.Pages[i]))
{
string texturePath = Path.Combine(bmfFile.Path, bmfFile.Pages[i]);
string texturePath = Path.Combine(Path.GetDirectoryName(bmfFile.Path), bmfFile.Pages[i]);
using (Stream textureStream = File.OpenRead(texturePath))
{
Texture2D texture = Texture2D.FromStream(graphicsDevice, textureStream);
@@ -60,6 +60,8 @@ public static class BitmapFontFileReader
_ => throw new InvalidOperationException("This does not appear to be a valid BMFont file!")
};
bmfFile.Path = stream.Name;
return bmfFile;
}