fix: Fixes PooledRefList ToList returning wrong size (#1899)

### Summary

- Fixed a bug caused by a bad assumption. If `m_List[index]` is sparse and null values are casted, the server does not crash.
- Fixed a bug where `PooledRefList.ToList` extension method returned the wrong list size.
This commit is contained in:
Kamron Batman 2024-08-05 08:50:56 -07:00 committed by GitHub
parent a6a647551f
commit 5d9d1a2118
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -419,7 +419,7 @@ public static class Utility
// This requires copying the List, which is an O(n) operation.
public static List<R> ToList<T, R>(this PooledRefList<T> poolList) where T : R
{
var size = poolList._size;
var size = poolList.Count;
var items = poolList._items;
var list = new List<R>(size);
@ -428,7 +428,7 @@ public static class Utility
return list;
}
for (var i = 0; i < items.Length; i++)
for (var i = 0; i < size; i++)
{
list.Add(items[i]);
}

View file

@ -1274,7 +1274,10 @@ namespace Server.Gumps
i < 9 && index >= 0 && index < m_List.Count;
++i, ++index)
{
var a = (Account)m_List[index];
if (m_List[index] is not Account a)
{
continue;
}
var offset = 200 + i * 20;