NullReferenceException thrown when invoking TextMeasurer.MeasureBounds
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of Fonts
- I have verified if the problem exist in both
DEBUG
andRELEASE
mode - I have searched open and closed issues to ensure it has not already been reported
Description
The method TextMeasurer.MeasureBounds
throws a System.NullReferenceException
when using the OpenSans font.
Steps to Reproduce
I downloaded the OpenSans font from Google Fonts
The following code demonstrates the issue:
using SixLabors.Fonts;
var fontCollection = new FontCollection();
FontFamily fontFamily = fontCollection.Add("./OpenSans/OpenSans-Regular.ttf");
Font font = new Font(fontFamily, 100, FontStyle.Regular);
var rendererOptions = new TextOptions(font)
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
};
FontRectangle bounds = TextMeasurer.MeasureBounds(
"Hello World",
rendererOptions
);
The call to MeasureBounds
throws a NullReference
exception. Here are the exception details:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=SixLabors.Fonts
StackTrace:
at SixLabors.Fonts.Tables.AdvancedTypographic.GPosTable.GetFeatureLookups(Tag& stageFeature, ScriptClass script)
at SixLabors.Fonts.Tables.AdvancedTypographic.GPosTable.TryUpdatePositions(FontMetrics fontMetrics, GlyphPositioningCollection collection, KerningMode kerningMode, Boolean& kerned)
at SixLabors.Fonts.StreamFontMetrics.UpdatePositions(GlyphPositioningCollection collection, KerningMode kerningMode)
at SixLabors.Fonts.FileFontMetrics.UpdatePositions(GlyphPositioningCollection collection, KerningMode kerningMode)
at SixLabors.Fonts.TextLayout.ProcessText(ReadOnlySpan`1 text, TextOptions options)
at SixLabors.Fonts.TextLayout.GenerateLayout(ReadOnlySpan`1 text, TextOptions options)
at SixLabors.Fonts.TextMeasurer.TextMeasurerInt.MeasureBounds(ReadOnlySpan`1 text, TextOptions options)
at SixLabors.Fonts.TextMeasurer.MeasureBounds(String text, TextOptions options)
at Program.<Main>$(String[] args) in C:\Development\PlayArea\ImageSharp\MeasureBounds\MeasureBounds\Program.cs:line 11
System Configuration
- Fonts version: 1.0.0-beta 16 (I am not explicitly including it)
- Other Six Labors packages and versions:
- SixLabors.ImageSharp version 2.1.2
- SixLabors.ImageSharp.Drawing version 1.0.0-beta14
- Environment (Operating system, version and so on): Windows 10
- .NET Framework version: 6.0
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
c# - What is a NullReferenceException, and how do I fix it?
If the person does not have a title, this will throw an exception because it is trying to call ToUpper on a property...
Read more >NullReferenceException Class (System)
The exception that is thrown when there is an attempt to dereference a null object reference.
Read more >How to avoid NullReferenceException in C# | RIMdev Blog
This exception is thrown when you try to access any properties / methods/ indexes on a type of object which points to null....
Read more >c# - Determining the object that caused a null reference ...
To prevent an X/Y problem, the goal is to simply record what object causes a null reference exception to be thrown, since the...
Read more >Object Reference Not Set to an Instance of an Object
The following code will throw a NullReferenceException if the variable “text” being passed in is null. You can't call ToUpper() on a null...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I do think #266 is a duplicate since it was reported against 1.0.0-beta17.
The fix hasn’t been released to nuget yet, I haven’t tested the myget beta17.8 (https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.Fonts) but it would probably work since the fix was “obvious” 😄
Here is the file
OpenSans-Regular.ttf
that my example code was loading:OpenSans-Regular.zip