From ebe184b10c62f34fcdadc0ff76ae022f5871be69 Mon Sep 17 00:00:00 2001 From: Soreepeong <3614868+Soreepeong@users.noreply.github.com> Date: Thu, 7 Aug 2025 07:48:38 +0900 Subject: [PATCH] Handle nullptr/Span.Empty handling, add explicit overload for ImU8String.AppendFormatted(object) --- imgui/Dalamud.Bindings.ImGui/ImU8String.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/imgui/Dalamud.Bindings.ImGui/ImU8String.cs b/imgui/Dalamud.Bindings.ImGui/ImU8String.cs index 63ccbfb28..88858ca10 100644 --- a/imgui/Dalamud.Bindings.ImGui/ImU8String.cs +++ b/imgui/Dalamud.Bindings.ImGui/ImU8String.cs @@ -35,7 +35,7 @@ public ref struct ImU8String : IDisposable } public ImU8String(int literalLength, int formattedCount) - : this(ReadOnlySpan.Empty) + : this(""u8) { this.state |= State.Interpolation; literalLength += formattedCount * 4; @@ -51,6 +51,12 @@ public ref struct ImU8String : IDisposable public ImU8String(ReadOnlySpan text, bool ensureNullTermination = false) : this() { + if (Unsafe.IsNullRef(in MemoryMarshal.GetReference(text))) + { + this.state = State.None; + return; + } + this.state = State.Initialized; if (text.IsEmpty) { @@ -82,6 +88,12 @@ public ref struct ImU8String : IDisposable public ImU8String(ReadOnlySpan text) : this() { + if (Unsafe.IsNullRef(in MemoryMarshal.GetReference(text))) + { + this.state = State.None; + return; + } + this.state = State.Initialized | State.NullTerminated; this.Length = Encoding.UTF8.GetByteCount(text); if (this.Length + 1 < AllocFreeBufferSize) @@ -313,6 +325,12 @@ public ref struct ImU8String : IDisposable FixAlignment(startingPos, alignment); } + public void AppendFormatted(object? value) => this.AppendFormatted(value!); + public void AppendFormatted(object? value, string? format) => this.AppendFormatted(value!, format); + public void AppendFormatted(object? value, int alignment) => this.AppendFormatted(value!, alignment); + public void AppendFormatted(object? value, int alignment, string? format) => + this.AppendFormatted(value!, alignment, format); + public void AppendFormatted(T value) => this.AppendFormatted(value, null); public void AppendFormatted(T value, string? format)