From f4795fd389daec5aa3ae93e2193e2f0d022d9ac6 Mon Sep 17 00:00:00 2001 From: Nya Date: Fri, 10 May 2019 19:32:22 +0300 Subject: [PATCH] fixed Menu concurrency issue --- Menu/Menu.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Menu/Menu.cs b/Menu/Menu.cs index 5391109..298c6dc 100644 --- a/Menu/Menu.cs +++ b/Menu/Menu.cs @@ -14,6 +14,7 @@ namespace Ensage.Common.Menu { using System; + using System.Collections.Concurrent; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -109,7 +110,7 @@ static Menu() MenuPanel = new DrawRect(Color.Black); PanelText = new DrawText { Text = "EnsageSharp Menu", FontFlags = FontFlags.AntiAlias }; TextureDictionary = new Dictionary(); - ItemDictionary = new Dictionary(); + ItemDictionary = new ConcurrentDictionary(); Drawing.OnDraw += OnDraw; ActivateCommonMenu(); } @@ -149,10 +150,8 @@ public Menu( this.ShowTextWithTexture = showTextWithTexture; this.transition = new ExpoEaseInOut(0.25); - if (Root?.Item("allowCustomTextures").GetValue() != true) - { + if (!Root?.Item("allowCustomTextures").GetValue() ?? false) this.TextureName = null; - } AppDomain.CurrentDomain.DomainUnload += delegate { this.SaveAll(); }; AppDomain.CurrentDomain.ProcessExit += delegate { this.SaveAll(); }; @@ -301,7 +300,7 @@ public string TextureName { /// /// The item dictionary. /// - internal static Dictionary ItemDictionary { get; set; } + internal static ConcurrentDictionary ItemDictionary { get; set; } /// Gets or sets the menu panel. internal static DrawRect MenuPanel { get; set; } @@ -817,10 +816,7 @@ public MenuItem Item(string name, bool makeChampionUniq = false) ?? (from subMenu in this.Children where subMenu.Item(name) != null select subMenu.Item(name)) .FirstOrDefault(); if (tempItem != null) - { - ItemDictionary.Add(id, tempItem); - } - + ItemDictionary.TryAdd(id, tempItem); return tempItem; }