From 78f06a23599e6505c865a5a75404acd3e3516f70 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Mon, 20 Jan 2025 23:13:56 +0300 Subject: [PATCH] Fix null reference exception in TextCommand. --- Dashboard.Drawing/TextExtension.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Dashboard.Drawing/TextExtension.cs b/Dashboard.Drawing/TextExtension.cs index 253b8f0..1ea0d7d 100644 --- a/Dashboard.Drawing/TextExtension.cs +++ b/Dashboard.Drawing/TextExtension.cs @@ -7,10 +7,11 @@ namespace Dashboard.Drawing { public class TextExtension : DrawExtension { - public TextCommand TextCommand { get; } = new TextCommand(); + public TextCommand TextCommand { get; } private TextExtension() : base("DB_Text", new [] { FontExtension.Instance, BrushExtension.Instance }) { + TextCommand = new TextCommand(this); } public static readonly TextExtension Instance = new TextExtension(); @@ -19,12 +20,17 @@ namespace Dashboard.Drawing public class TextCommand : IDrawCommand { public string Name { get; } = "Text"; - public IDrawExtension Extension { get; } = TextExtension.Instance; + public IDrawExtension Extension { get; } public int Length { get; } = -1; + public TextCommand(TextExtension ext) + { + Extension = ext; + } + public int WriteParams(DrawQueue queue, TextCommandArgs obj, Span param) { - int size = Unsafe.SizeOf
() + obj.Text.Length + sizeof(char); + int size = Unsafe.SizeOf
() + obj.Text.Length * sizeof(char) + sizeof(char); if (param.Length < size) return size; @@ -52,7 +58,7 @@ namespace Dashboard.Drawing Header header = MemoryMarshal.Cast(param[0..Unsafe.SizeOf
()])[0]; ReadOnlySpan text = MemoryMarshal.Cast(param[Unsafe.SizeOf
()..]); - if (header.BorderBrush == -1 || header.BorderRadius == 0) + if (header.BorderBrush != -1 && header.BorderRadius != 0) { return new TextCommandArgs( (IFont)queue.Resources[header.Font],