@@ -94,23 +94,37 @@ private LocalCollectionId AllocateNextId ()
9494
9595 /// <summary> Default enumeration skips the empty collection. </summary>
9696 public IEnumerator < ModCollection > GetEnumerator ( )
97- => _collections . Skip ( 1 ) . GetEnumerator ( ) ;
97+ => GetModSnapShot ( ) . ToList ( ) . GetEnumerator ( ) ;
9898
9999 IEnumerator IEnumerable . GetEnumerator ( )
100100 => GetEnumerator ( ) ;
101101
102102 public int Count
103- => _collections . Count ;
103+ {
104+ get
105+ {
106+ lock ( _collectionsLock )
107+ return _collections . Count ;
108+ }
109+ }
104110
105111 public ModCollection this [ int index ]
106- => _collections [ index ] ;
112+ {
113+ get
114+ {
115+ lock ( _collectionsLock )
116+ return _collections [ index ] ;
117+ }
118+ }
107119
108120 /// <summary> Find a collection by its name. If the name is empty or None, the empty collection is returned. </summary>
109121 public bool ByName ( string name , [ NotNullWhen ( true ) ] out ModCollection ? collection )
110122 {
111123 if ( name . Length != 0 )
112- return _collections . FindFirst ( c => string . Equals ( c . Identity . Name , name , StringComparison . OrdinalIgnoreCase ) , out collection ) ;
113-
124+ lock ( _collectionsLock )
125+ {
126+ return _collections . FindFirst ( c => string . Equals ( c . Identity . Name , name , StringComparison . OrdinalIgnoreCase ) , out collection ) ;
127+ }
114128 collection = ModCollection . Empty ;
115129 return true ;
116130 }
@@ -119,8 +133,10 @@ public bool ByName(string name, [NotNullWhen(true)] out ModCollection? collectio
119133 public bool ById ( Guid id , [ NotNullWhen ( true ) ] out ModCollection ? collection )
120134 {
121135 if ( id != Guid . Empty )
122- return _collections . FindFirst ( c => c . Identity . Id == id , out collection ) ;
123-
136+ lock ( _collectionsLock )
137+ {
138+ return _collections . FindFirst ( c => c . Identity . Id == id , out collection ) ;
139+ }
124140 collection = ModCollection . Empty ;
125141 return true ;
126142 }
@@ -189,7 +205,7 @@ public bool AddCollection(string name, ModCollection? duplicate)
189205 /// </summary>
190206 public bool RemoveCollection ( ModCollection collection )
191207 {
192- if ( collection . Identity . Index <= ModCollection . Empty . Identity . Index || collection . Identity . Index >= _collections . Count )
208+ if ( collection . Identity . Index <= ModCollection . Empty . Identity . Index || collection . Identity . Index >= Count )
193209 {
194210 Penumbra . Messager . NotificationMessage ( "Can not remove the empty collection." , NotificationType . Error , false ) ;
195211 return false ;
@@ -322,12 +338,12 @@ private ModCollection SetDefaultNamedCollection()
322338 return collection ;
323339
324340 if ( AddCollection ( ModCollectionIdentity . DefaultCollectionName , null ) )
325- return _collections [ ^ 1 ] ;
341+ return this [ ^ 1 ] ;
326342
327343 Penumbra . Messager . NotificationMessage (
328344 $ "Unknown problem creating a collection with the name { ModCollectionIdentity . DefaultCollectionName } , which is required to exist.",
329345 NotificationType . Error ) ;
330- return Count > 1 ? _collections [ 1 ] : _collections [ 0 ] ;
346+ return Count > 1 ? this [ 1 ] : this [ 0 ] ;
331347 }
332348
333349 /// <summary> Move all settings in all collections to unused settings. </summary>
0 commit comments