diff --git a/HellionChat/Ui/Popout.cs b/HellionChat/Ui/Popout.cs index 1de5c6c..a2f34f8 100644 --- a/HellionChat/Ui/Popout.cs +++ b/HellionChat/Ui/Popout.cs @@ -80,7 +80,10 @@ internal class Popout : Window if (!Tab.CanResize) Flags |= ImGuiWindowFlags.NoResize; - if (!ChatLogWindow.PopOutDocked[Idx]) + // Idx may point past the end if PopOutDocked was resized (e.g., a tab + // dropped) between the AddPopOutsToDraw() snapshot and this frame. + // Guard the read so we don't index into stale state. + if (Idx >= 0 && Idx < ChatLogWindow.PopOutDocked.Count && !ChatLogWindow.PopOutDocked[Idx]) { if (Tab.IndependentOpacity) { @@ -195,7 +198,8 @@ internal class Popout : Window public override void PostDraw() { - ChatLogWindow.PopOutDocked[Idx] = ImGui.IsWindowDocked(); + if (Idx >= 0 && Idx < ChatLogWindow.PopOutDocked.Count) + ChatLogWindow.PopOutDocked[Idx] = ImGui.IsWindowDocked(); if (Plugin.Config is { OverrideStyle: true, ChosenStyle: not null }) StyleModel.GetConfiguredStyles()?.FirstOrDefault(style => style.Name == Plugin.Config.ChosenStyle)?.Pop(); diff --git a/HellionChat/Ui/SettingsTabs/Tabs.cs b/HellionChat/Ui/SettingsTabs/Tabs.cs index ab46587..8ad2bb0 100755 --- a/HellionChat/Ui/SettingsTabs/Tabs.cs +++ b/HellionChat/Ui/SettingsTabs/Tabs.cs @@ -181,28 +181,39 @@ internal sealed class Tabs : ISettingsTab ImGui.SameLine(); - var selectedWorld = worlds.FindIndex(world => world.RowId == tab.TellTarget.World); - if (selectedWorld == -1) - selectedWorld = 0; - - using (var combo = ImRaii.Combo("###player-world", worlds[selectedWorld].Name.ToString())) + // Guard against an empty worlds list — can happen briefly + // when switching characters or if the datacenter sheet + // has not yet populated. Without the guard the indexed + // access into worlds[selectedWorld] would crash. + if (worlds.Count == 0) { - if (combo.Success) + ImGui.TextDisabled("(no worlds available)"); + } + else + { + var selectedWorld = worlds.FindIndex(world => world.RowId == tab.TellTarget.World); + if (selectedWorld == -1) + selectedWorld = 0; + + using (var combo = ImRaii.Combo("###player-world", worlds[selectedWorld].Name.ToString())) { - var lastDc = worlds.First().DataCenter.RowId; - foreach (var (idx, world) in worlds.Index()) + if (combo.Success) { - if (ImGui.Selectable(world.Name.ToString(), selectedWorld == idx)) + var lastDc = worlds.First().DataCenter.RowId; + foreach (var (idx, world) in worlds.Index()) { - selectedWorld = idx; - tab.TellTarget.World = worlds[selectedWorld].RowId; + if (ImGui.Selectable(world.Name.ToString(), selectedWorld == idx)) + { + selectedWorld = idx; + tab.TellTarget.World = worlds[selectedWorld].RowId; + } + + if (lastDc == world.DataCenter.RowId) + continue; + + lastDc = world.DataCenter.RowId; + ImGui.Separator(); } - - if (lastDc == world.DataCenter.RowId) - continue; - - lastDc = world.DataCenter.RowId; - ImGui.Separator(); } } }