LabAPI
LabAPI copied to clipboard
[BUG] Clearing inventory gives InvalidOperationException
When clearing the inventory of a player, it raises an InvalidOperationException. Only the first item is removed, and if this is done during an event the player is instantly kicked.
A possible fix would be cloning the item list in the Player.ClearItems() method and looping over this list instead.
Related exception:
[2025-04-09 19:07:02.037 +02:00] [STDOUT] InvalidOperationException: Collection was modified; enumeration operation may not execute.
[2025-04-09 19:07:02.038 +02:00] [STDOUT] at System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[TKey,TValue].MoveNext () [0x00013] in <05089c1b6989455fb1452c627044bac4>:0
[2025-04-09 19:07:02.038 +02:00] [STDOUT] at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00029] in <a3536978e9984063a5ca6c790db4d471>:0
[2025-04-09 19:07:02.038 +02:00] [STDOUT] at LabApi.Features.Wrappers.Player.ClearItems () [0x0001c] in <55a16b597ad7463da126996d837dfaa8>:0
[2025-04-09 19:07:02.038 +02:00] [STDOUT] at LabApi.Features.Wrappers.Player.ClearInventory (System.Boolean clearAmmo, System.Boolean clearItems) [0x0000c] in <55a16b597ad7463da126996d837dfaa8>:0
Fixed in https://github.com/northwood-studios/LabAPI/pull/84
Resolved