From ce7dda9e48739b4a326a154d8b4c56923ead1a65 Mon Sep 17 00:00:00 2001 From: Jon Kazama Date: Thu, 21 May 2026 18:15:12 +0200 Subject: [PATCH] fix(ui): null-guard agent access and refocus input after token insert AgentMap.Instance() and AgentChatLog.Instance() can return null during zone transitions. Capture pointers into locals and short-circuit the FlagMarkerCount/LinkedItem deref when null so the entries are correctly greyed out without faulting. Add Activate/ActivatePos after each append so the input box regains focus and the caret lands after the token, matching the SymbolPicker and AutoComplete insert paths. --- HellionChat/Ui/ChatLogWindow.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/HellionChat/Ui/ChatLogWindow.cs b/HellionChat/Ui/ChatLogWindow.cs index 9318935..072cb5f 100644 --- a/HellionChat/Ui/ChatLogWindow.cs +++ b/HellionChat/Ui/ChatLogWindow.cs @@ -1130,18 +1130,29 @@ public sealed class ChatLogWindow : Window // so the inserted token cannot expand to nothing. unsafe { - var flagSet = AgentMap.Instance()->FlagMarkerCount > 0; + // Null-check before deref: pointers can be null during zone transitions. + var agentMap = AgentMap.Instance(); + var flagSet = agentMap != null && agentMap->FlagMarkerCount > 0; using (ImRaii.Disabled(!flagSet)) { if (ImGui.Selectable(HellionStrings.ChatLog_Insert_MapFlag)) + { Chat += ""; + Activate = true; + ActivatePos = Chat.Length; + } } - var itemSet = AgentChatLog.Instance()->LinkedItem.ItemId != 0; + var agentChat = AgentChatLog.Instance(); + var itemSet = agentChat != null && agentChat->LinkedItem.ItemId != 0; using (ImRaii.Disabled(!itemSet)) { if (ImGui.Selectable(HellionStrings.ChatLog_Insert_ItemLink)) + { Chat += ""; + Activate = true; + ActivatePos = Chat.Length; + } } } }