Sometimes when you click the text tool for the first time an exception will be raised and caught with this text (in debug mode):
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
at Pinta.Core.FontManager.GetSizes (Pango.FontFace fontFace) [0x00024] in /home/rpvn/vcs/Pinta/Pinta.Core/Managers/FontManager.cs:81
at Pinta.Core.FontManager.GetSizes (Pango.FontFamily family) [0x00000] in /home/rpvn/vcs/Pinta/Pinta.Core/Managers/FontManager.cs:64
at Pinta.Tools.TextTool.UpdateFontSizes () [0x0002d] in /home/rpvn/vcs/Pinta/Pinta.Tools/Tools/TextTool/TextTool.cs:252
at Pinta.Tools.TextTool.OnBuildToolBar (Gtk.Toolbar tb) [0x00652] in /home/rpvn/vcs/Pinta/Pinta.Tools/Tools/TextTool/TextTool.cs:209
at Pinta.Core.BaseTool.DoBuildToolBar (Gtk.Toolbar tb) [0x00000] in /home/rpvn/vcs/Pinta/Pinta.Core/Classes/BaseTool.cs:95
at Pinta.Core.ToolManager.SetCurrentTool (Pinta.Core.BaseTool tool) [0x0009d] in /home/rpvn/vcs/Pinta/Pinta.Core/Managers/ToolManager.cs:124
at Pinta.Core.ToolManager.HandlePbToolItemClicked (System.Object sender, System.EventArgs e) [0x00053] in /home/rpvn/vcs/Pinta/Pinta.Core/Managers/ToolManager.cs:75
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod*,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d5] in /usr/src/packages/BUILD/mono-2.8.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:223
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000f0] in /usr/src/packages/BUILD/mono-2.8.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:231
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /usr/src/packages/BUILD/mono-2.8.2/mcs/class/corlib/System.Reflection/MethodBase.cs:96
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000bf] in /usr/src/packages/BUILD/mono-2.8.2/mcs/class/corlib/System/Delegate.cs:401
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00018] in /usr/src/packages/BUILD/mono-2.8.2/mcs/class/corlib/System/MulticastDelegate.cs:69
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /usr/src/packages/BUILD/mono-2.8.2/mcs/class/corlib/System/Delegate.cs:375
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x0004f] in /usr/src/packages/BUILD/gtk-sharp-2.12.10/glib/Signal.cs:195
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x0000c] in /usr/src/packages/BUILD/gtk-sharp-2.12.10/glib/SignalClosure.cs:118
at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00075] in /usr/src/packages/BUILD/gtk-sharp-2.12.10/glib/SignalClosure.cs:146
This would appear to be because the fonts aren't finished initializing or something similar. After closing the exception window you can type text but not change font size. If you change to a different font type and then back again, you can change font size. (Probably initialized by then.)
The fix is probably to catch the exception earlier and substitute the default font size.
OK, there is something wrong with the underlying Pango library (or pango-sharp which is the gobetween).
When you call this method in FontManager.cs, it's supposedto return nsizes = 0 if the font is not a bitmap font. (Most fonts are vector fonts these days, so they will return 0)
// Query for supported sizes for this font
fontFace.ListSizes (out sizes, out nsizes);
if (nsizes == 0)
return default_font_sizes;
List<int> result = new List<int> ();
for (int i = 0; i < nsizes; i++)
result.Add (*(&sizes + 4 * i)); //Here's where things go wrong....
However, sometimes it returns garbage like 32767 which means it's returning uninitialized values, but that will still pass the check. Now, putting a try/catch around the function trying to recover the sizes will work in debug mode and catch the nullreference exception, but not when you run without debug because such things aren't checked then. (And then the font menu is filled with gibberish numbers.)
There is a real ugly hack that can fix this, but I'm not sure I want to do it:
//Ugly hack to deal with pango returning garbage when not finished initiliazing
if (nsizes <= 0 || nsizes > 200)
return default_font_sizes;
Is it worth it to try and chase this down further or should we just do it the easy way?