From ee50994b3984c93392fce8a5b73779a91bb77fd0 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 1 May 2023 22:50:34 +0200 Subject: [PATCH] Maybe sort race condition. --- Penumbra/Collections/Cache/CollectionCacheManager.cs | 7 +++++-- Penumbra/Collections/Manager/ActiveCollections.cs | 2 +- .../Collections/Manager/IndividualCollections.Files.cs | 2 +- Penumbra/Collections/Manager/IndividualCollections.cs | 4 +++- Penumbra/Collections/Manager/TempCollectionManager.cs | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Penumbra/Collections/Cache/CollectionCacheManager.cs b/Penumbra/Collections/Cache/CollectionCacheManager.cs index 5a4ab2dd..001ea952 100644 --- a/Penumbra/Collections/Cache/CollectionCacheManager.cs +++ b/Penumbra/Collections/Cache/CollectionCacheManager.cs @@ -42,6 +42,8 @@ public CollectionCacheManager(FrameworkManager framework, CommunicatorService co _active = active; _storage = storage; + if (!_active.Individuals.IsLoaded) + _active.Individuals.Loaded += CreateNecessaryCaches; _communicator.CollectionChange.Subscribe(OnCollectionChange, -100); _communicator.ModPathChanged.Subscribe(OnModChangeAddition, -100); _communicator.ModPathChanged.Subscribe(OnModChangeRemoval, 100); @@ -49,11 +51,11 @@ public CollectionCacheManager(FrameworkManager framework, CommunicatorService co _communicator.ModOptionChanged.Subscribe(OnModOptionChange, -100); _communicator.ModSettingChanged.Subscribe(OnModSettingChange); _communicator.CollectionInheritanceChanged.Subscribe(OnCollectionInheritanceChange); - CreateNecessaryCaches(); - _active.Individuals.Loaded += CreateNecessaryCaches; if (!MetaFileManager.CharacterUtility.Ready) MetaFileManager.CharacterUtility.LoadingFinished += IncrementCounters; + + CreateNecessaryCaches(); } public void Dispose() @@ -303,6 +305,7 @@ private void CreateNecessaryCaches() .Select(c => Task.Run(() => CalculateEffectiveFileListInternal(c))) .ToArray(); + Penumbra.Log.Debug($"Creating {tasks.Length} necessary caches."); Task.WaitAll(tasks); } } diff --git a/Penumbra/Collections/Manager/ActiveCollections.cs b/Penumbra/Collections/Manager/ActiveCollections.cs index 19aa27cd..1034227e 100644 --- a/Penumbra/Collections/Manager/ActiveCollections.cs +++ b/Penumbra/Collections/Manager/ActiveCollections.cs @@ -43,7 +43,7 @@ public ActiveCollections(Configuration config, CollectionStorage storage, ActorS Current = storage.DefaultNamed; Default = storage.DefaultNamed; Interface = storage.DefaultNamed; - Individuals = new IndividualCollections(actors, config); + Individuals = new IndividualCollections(actors, config, false); _communicator.CollectionChange.Subscribe(OnCollectionChange, -100); LoadCollections(); UpdateCurrentCollectionInUse(); diff --git a/Penumbra/Collections/Manager/IndividualCollections.Files.cs b/Penumbra/Collections/Manager/IndividualCollections.Files.cs index 0ab9cbfb..4e238722 100644 --- a/Penumbra/Collections/Manager/IndividualCollections.Files.cs +++ b/Penumbra/Collections/Manager/IndividualCollections.Files.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Dalamud.Game; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Interface.Internal.Notifications; using Newtonsoft.Json.Linq; @@ -37,6 +36,7 @@ void Func() { if (ReadJObjectInternal(obj, storage)) saver.ImmediateSave(parent); + IsLoaded = true; Loaded.Invoke(); _actorService.FinishedCreation -= Func; }); diff --git a/Penumbra/Collections/Manager/IndividualCollections.cs b/Penumbra/Collections/Manager/IndividualCollections.cs index 8708df11..a3005f07 100644 --- a/Penumbra/Collections/Manager/IndividualCollections.cs +++ b/Penumbra/Collections/Manager/IndividualCollections.cs @@ -18,14 +18,16 @@ public sealed partial class IndividualCollections private readonly Dictionary _individuals = new(); public event Action Loaded; + public bool IsLoaded { get; private set; } public IReadOnlyList<(string DisplayName, IReadOnlyList Identifiers, ModCollection Collection)> Assignments => _assignments; - public IndividualCollections(ActorService actorService, Configuration config) + public IndividualCollections(ActorService actorService, Configuration config, bool temporary) { _config = config; _actorService = actorService; + IsLoaded = temporary; Loaded += () => Penumbra.Log.Information($"{_assignments.Count} Individual Assignments loaded after delay."); } diff --git a/Penumbra/Collections/Manager/TempCollectionManager.cs b/Penumbra/Collections/Manager/TempCollectionManager.cs index 0416b4b7..7f1f03b8 100644 --- a/Penumbra/Collections/Manager/TempCollectionManager.cs +++ b/Penumbra/Collections/Manager/TempCollectionManager.cs @@ -25,7 +25,7 @@ public TempCollectionManager(Configuration config, CommunicatorService communica _communicator = communicator; _actors = actors; _storage = storage; - Collections = new IndividualCollections(actors, config); + Collections = new IndividualCollections(actors, config, true); _communicator.TemporaryGlobalModChange.Subscribe(OnGlobalModChange); }