From 66b9705837eee873db347248ab1faa60ff3f5874 Mon Sep 17 00:00:00 2001 From: Laurens de Voogd Date: Thu, 15 Oct 2026 09:59:41 +0200 Subject: [PATCH] Return null from GlfwBackend.GetClipboardText when the clipboard holds no text glfwGetClipboardString returns NULL when the clipboard cannot be converted to text (GLFW_FORMAT_UNAVAILABLE), and Glfw.Clipboard is declared string? for it. Passing that null to Utf8.GetByteCount threw ArgumentNullException inside the native callback, which ended the process on Ctrl+V. ImGui treats a null clipboard as nothing to paste, as with the C++ imgui_impl_glfw. Fixes #8 Signed-off-by: Laurens de Voogd --- Brutal.ImGui.Backends/PlatformBackends/GlfwBackend.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Brutal.ImGui.Backends/PlatformBackends/GlfwBackend.cs b/Brutal.ImGui.Backends/PlatformBackends/GlfwBackend.cs index e5e3032..ad0cfb2 100644 --- a/Brutal.ImGui.Backends/PlatformBackends/GlfwBackend.cs +++ b/Brutal.ImGui.Backends/PlatformBackends/GlfwBackend.cs @@ -277,6 +277,9 @@ public partial class GlfwBackend : IPlatformBackend private unsafe byte* GetClipboardText(ImGuiContextPtr context) { var str = Glfw.Clipboard; + if (str is null) + return null; + var byteCount = Utf8.GetByteCount(str); _cachedClipboardText.Count = byteCount + 1; Utf8.FromUtf16(str, _cachedClipboardText.AsSpan(), out _, out _);