bugfix: moved validation inside lock

This commit is contained in:
mayo 2025-11-01 17:20:16 -04:00
parent 0bf9fdea84
commit 1d7603bb8c
No known key found for this signature in database
GPG key ID: 5B138E78344184A6

View file

@ -200,6 +200,8 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
/// Remove the given collection if it exists and is neither the empty nor the default-named collection. /// Remove the given collection if it exists and is neither the empty nor the default-named collection.
/// </summary> /// </summary>
public bool RemoveCollection(ModCollection collection) public bool RemoveCollection(ModCollection collection)
{
lock (_collectionsLock)
{ {
if (collection.Identity.Index <= ModCollection.Empty.Identity.Index || collection.Identity.Index >= Count) if (collection.Identity.Index <= ModCollection.Empty.Identity.Index || collection.Identity.Index >= Count)
{ {
@ -215,8 +217,7 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
Delete(collection); Delete(collection);
_saveService.ImmediateDelete(new ModCollectionSave(_modStorage, collection)); _saveService.ImmediateDelete(new ModCollectionSave(_modStorage, collection));
lock (_collectionsLock)
{
_collections.RemoveAt(collection.Identity.Index); _collections.RemoveAt(collection.Identity.Index);
// Update indices. // Update indices.
for (var i = collection.Identity.Index; i < _collections.Count; ++i) for (var i = collection.Identity.Index; i < _collections.Count; ++i)