fix: prevent crash from duplicate keys

This commit is contained in:
Anna 2020-08-08 22:15:46 -04:00
parent 3b9bf011e1
commit 33dbff01b2

View File

@ -330,10 +330,15 @@ namespace PeepingTom {
// create a dictionary for O(1) lookups by actor id // create a dictionary for O(1) lookups by actor id
Dictionary<int, Actor> actors = null; Dictionary<int, Actor> actors = null;
if (targeting.Count + (previousTargeters?.Count ?? 0) > 1) { if (targeting.Count + (previousTargeters?.Count ?? 0) > 1) {
actors = this.plugin.Interface.ClientState.Actors Dictionary<int, Actor> dict = new Dictionary<int, Actor>();
// only take into account players foreach (Actor actor in this.plugin.Interface.ClientState.Actors) {
.Where(actor => actor.ObjectKind == Dalamud.Game.ClientState.Actors.ObjectKind.Player) if (dict.ContainsKey(actor.ActorId) || actor.ObjectKind != Dalamud.Game.ClientState.Actors.ObjectKind.Player) {
.ToDictionary(actor => actor.ActorId); continue;
}
dict.Add(actor.ActorId, actor);
}
actors = dict;
} }
ImGuiWindowFlags flags = ImGuiWindowFlags.AlwaysAutoResize; ImGuiWindowFlags flags = ImGuiWindowFlags.AlwaysAutoResize;