From 5b0a0432418a715dd4d62fe86905f23696a33123 Mon Sep 17 00:00:00 2001 From: rushtothesun <20650932+rushtothesun@users.noreply.github.com> Date: Fri, 14 Nov 2025 00:49:05 -0600 Subject: [PATCH] Fix Crash when shrinking the window past profiles --- ReAgent.cs | 83 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/ReAgent.cs b/ReAgent.cs index f42112f..681600f 100644 --- a/ReAgent.cs +++ b/ReAgent.cs @@ -189,48 +189,67 @@ public override void DrawSettings() if (tabSelected) { - _pendingNames.TryGetValue(profile, out var newProfileName); - newProfileName ??= profileName; - ImGui.InputText("Name", ref newProfileName, 40); - if (!isCurrentProfile) + try { - using (ImGuiHelpers.UseStyleColor(ImGuiCol.Button, Color.Green.ToImgui())) - if (ImGui.Button("Activate")) - { - Settings.CurrentProfile = profileName; - } - - ImGui.SameLine(); - } - - if (ImGui.Button("Export profile")) - { - ImGui.SetClipboardText(DataExporter.ExportDataBase64(profile, "reagent_profile_v1", new JsonSerializerSettings())); - } - - if (profileName != newProfileName) - { - if (Settings.Profiles.ContainsKey(newProfileName)) + // Check if there's minimum space available to render UI safely + var availableSpace = ImGui.GetContentRegionAvail(); + if (availableSpace.X < 100 || availableSpace.Y < 50) { - ImGui.SameLine(); - ImGui.TextColored(Color.Red.ToImguiVec4(), "This profile name is already used"); - _pendingNames.AddOrUpdate(profile, newProfileName); + ImGui.TextColored(Color.Yellow.ToImguiVec4(), "Window too small - expand to view settings"); + ImGui.EndTabItem(); } else { - Settings.Profiles.Remove(profileName); - Settings.Profiles.Add(newProfileName, profile); - if (isCurrentProfile) + _pendingNames.TryGetValue(profile, out var newProfileName); + newProfileName ??= profileName; + ImGui.InputText("Name", ref newProfileName, 40); + if (!isCurrentProfile) { - Settings.CurrentProfile = newProfileName; + using (ImGuiHelpers.UseStyleColor(ImGuiCol.Button, Color.Green.ToImgui())) + if (ImGui.Button("Activate")) + { + Settings.CurrentProfile = profileName; + } + + ImGui.SameLine(); } - _pendingNames.Clear(); + if (ImGui.Button("Export profile")) + { + ImGui.SetClipboardText(DataExporter.ExportDataBase64(profile, "reagent_profile_v1", new JsonSerializerSettings())); + } + + if (profileName != newProfileName) + { + if (Settings.Profiles.ContainsKey(newProfileName)) + { + ImGui.SameLine(); + ImGui.TextColored(Color.Red.ToImguiVec4(), "This profile name is already used"); + _pendingNames.AddOrUpdate(profile, newProfileName); + } + else + { + Settings.Profiles.Remove(profileName); + Settings.Profiles.Add(newProfileName, profile); + if (isCurrentProfile) + { + Settings.CurrentProfile = newProfileName; + } + + _pendingNames.Clear(); + } + } + + profile.DrawSettings(_state, Settings); + ImGui.EndTabItem(); } } - - profile.DrawSettings(_state, Settings); - ImGui.EndTabItem(); + catch (Exception ex) + { + LogError($"Error rendering profile settings: {ex.Message}"); + ImGui.TextColored(Color.Red.ToImguiVec4(), "Error rendering - check logs"); + ImGui.EndTabItem(); + } } else {