From 3ca0a3ef2aafbca7afe846c69489b0ee75cd1c53 Mon Sep 17 00:00:00 2001 From: Christopher Whitley <103014489+AristurtleDev@users.noreply.github.com> Date: Thu, 11 Jul 2024 22:24:34 -0400 Subject: [PATCH] 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 --- source/MonoGame.Extended/BitmapFonts/BitmapFont.cs | 4 ++-- .../Content/BitmapFonts/BitmapFontFileReader.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/MonoGame.Extended/BitmapFonts/BitmapFont.cs b/source/MonoGame.Extended/BitmapFonts/BitmapFont.cs index d39372f3..b982c571 100644 --- a/source/MonoGame.Extended/BitmapFonts/BitmapFont.cs +++ b/source/MonoGame.Extended/BitmapFonts/BitmapFont.cs @@ -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); diff --git a/source/MonoGame.Extended/Content/BitmapFonts/BitmapFontFileReader.cs b/source/MonoGame.Extended/Content/BitmapFonts/BitmapFontFileReader.cs index acc77246..6f578477 100644 --- a/source/MonoGame.Extended/Content/BitmapFonts/BitmapFontFileReader.cs +++ b/source/MonoGame.Extended/Content/BitmapFonts/BitmapFontFileReader.cs @@ -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; }